Possible Duplicate:
PHP: The Reflection API - Great Addition To PHP With Little Use
Finding documentation is one problem, but the quality of documentation is another, equally important, problem. Most developers know the value of accurately commented code, but when i am in the middle of coding, the meaning of your code always seems crystal clear, so comments appear superfluous. Besides, there’s always the ultimate excuse for the absence of internal documentation—i want to keep file size small to reduce download time.
This is often the situation with internal documentation, but external documentation fares no better. It doesn’t make sense to write it as i go because things always change, but, by the time i’ve finished coding, documentation is the furthest thing from my mind.
However: I searched in google and I found a solution called Reflection Classes Could any one describe it briefly plz ?
The ReflectionClass::getProperties() function is an inbuilt function in PHP which is used to return an array of the reflected properties. Syntax: ReflectionClass::getProperties($filter) : array. Parameters: This function accepts a parameter filter which helps to remove some of the reflected properties.
::class ¶ The class keyword is also used for class name resolution. To obtain the fully qualified name of a class ClassName use ClassName::class . This is particularly useful with namespaced classes.
Basic reflections are quite fast - Reading methods and doc comments for 1000 classes cost just a few milliseconds. Parsing/Autoloading the classfiles does take a lot more time than the actual reflection mechanics.
Excerpt from the book Object-oriented PHP: concepts, techniques, and code By Peter Lavin:
This group of classes was created for the express purpose of introspecting other classes. These classes make it possible to examine the properties of other classes by retrieving metadata about classes; you can even use them to examine the reflection classes themselves.
Reflection provides information about the modifiers of a class or interface—whether that class is final or static, for example.
It can also reveal all the methods and data members of a class and all the modifiers applied to them.
Parameters passed to methods can also be introspected and the names of variables exposed. Through reflection it is possible to automate the documentation of built-in classes or user-defined classes.
It turns out that the central repository of information about classes was right in front of us all the time. PHP can tell us all about itself through the mirror of the reflection classes.
The reflection group of classes or Application Programming Interface (API) is made up of a number of different classes and one
interface, shown here:
class Reflection
interface Reflector
class ReflectionException extends Exception
class ReflectionFunction implements Reflector
class ReflectionParameter implements Reflector
class ReflectionMethod extends ReflectionFunction
class ReflectionClass implements Reflector
class ReflectionObject extends ReflectionClass
class ReflectionProperty implements Reflector
class ReflectionExtension implements Reflector
Look at this list, there is actually no class ancestor common to all reflection classes. On the other hand, the Reflector interface is shared by all classes except Reflection and ReflectionException.
ReflectionMethod extendsReflectionFunction, ReflectionObject
extends ReflectionClass
, and ReflectionException
extends Exception.
ReflectionObject
shares all the methods of ReflectionClass; the only difference between these classes is that ReflectionObject takes a class instance rather than a class name as a parameter—using an instance, you can introspect a class without knowing anything about it, even its name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With