Solved

Purpose of PHP ReflectionClass Apart from Documenting

Posted on 2009-06-30
4
383 Views
Last Modified: 2013-12-13
Dear all,

   I'm new to the concept of reflection. I have read into the concept but I'm not sure why it should be used apart from documenting the code.

   Invoking a method of a certain class via PHP ReflectionClass is more complicated than simply invoking the method by instantiating the class itself. So, why is ReflectionClass necessary?

   I understand that reflection can avoid hardcoding. Could you offer some examples of using the PHP ReflectionClass which makes coding more efficient?

Regards,
Ming
0
Comment
Question by:tsuiwaiming
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24745930
It is used in metaprogramming, i.e. when "programming the program".

http://en.wikipedia.org/wiki/Metaprogramming

You can find some examples of the usage here:

http://php.net/oop5.reflection 
0
 

Author Comment

by:tsuiwaiming
ID: 24746444
Dear cxr,

   Thanks for your message. I had read briefly the articles in the sources you offered while I was writing my question, though. May I clarify my question a bit? I'd like to know how PHP ReflectionClass helps in, say, a single webpage in which rows of a database are selected or updated.

Regards,
Ming
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24746622
I can't imagine how ReflectionClass would be helpfull in that scenario. I'm not saying it can not be helpfull, I just can't imagine how. :)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question