The ReflectionClass class lets you reverse-engineer classes.
<?php
class ReflectionClass implements Reflector {
public __construct(string name)
public string getName()
public bool isInternal()
public bool isUserDefined()
public string getFileName()
public int getStartLine()
public int getEndLine()
public string getDocComment()
public ReflectionMethod getConstructor()
public ReflectionMethod getMethod(string name)
public ReflectionMethod[] getMethods()
public ReflectionProperty getProperty(string name)
public ReflectionProperty[] getProperties()
public array getConstants()
public mixed getConstant(string name)
public bool isInstantiable()
public bool isInterface()
public bool isFinal()
public bool isAbstract()
public int getModifiers()
public bool isInstance(stdclass object)
public stdclass newInstance(mixed* args)
public ReflectionClass[] getInterfaces()
public ReflectionClass getParentClass()
public string toString()
public bool isSubclassOf(ReflectionClass class)
}
?> |
To introspect a class, you will first have to create an instance of the ReflectionClass class. You can then call any of the above methods on this instance.
Note: The method newInstance() accepts a variable number of arguments which are passed to the function just as in call_user_func().
Note: $class= new ReflectionClass('Foo'); $class->isInstance($arg) is equivalent to $arg instanceof Foo or is_a($arg, 'Foo').