counter.php. When you run the
above code, you will get the following output:
X-Powered-By: PHP/5.1.1
Content-type: text/html
===> The user-defined class 'Counter' [extends ReflectionClass::__set_state(array(
'name' => 'Object',
))]
declared in PHPDocument2
lines 15 to 29
having the modifiers 0 []
---> Documentation:
'/**
* A counter class
*/'
---> Implements:
array (
0 =>
ReflectionClass::__set_state(array(
'name' => 'NSerializable',
)),
)
---> Constants: array (
'START' => 0,
)
---> Properties: array (
0 =>
Chapter 5
[ 103 ]
ReflectionProperty::__set_state(array(
'name' => 'c',
'class' => 'Counter',
)),
)
---> Methods: array (
0 =>
ReflectionMethod::__set_state(array(
'name' => 'count',
'class' => 'Counter',
)),
)
---> $counter is instance? yes
---> new Object() is instance? No
ReflectionMethod
This is the class used to investigate any method of the class and then invoke it. Let us
see the structure of this class:
class ReflectionMethod extends ReflectionFunction
{
public __construct(mixed class, string name)
public string __toString()
public static string export(mixed class, string name, bool return)
public mixed invoke(stdclass object, mixed args)
public mixed invokeArgs(stdclass object, array args)
public bool isFinal()
public bool isAbstract()
public bool isPublic()
public bool isPrivate()
public bool isProtected()
public bool isStatic()
Reflection and Unit Testing
[ 104 ]
public bool isConstructor()
public bool isDestructor()
public int getModifiers()
public ReflectionClass getDeclaringClass()
// Inherited from ReflectionFunction
final private __clone()
public string getName()
public bool isInternal()
public bool isUserDefined()
public string getFileName()
public int getStartLine()
public int getEndLine()
public string getDocComment()
public array getStaticVariables()
public bool returnsReference()
public ReflectionParameter[] getParameters()
public int getNumberOfParameters()
public int getNumberOfRequiredParameters()
}
?>
The most important methods of this class are getNumberOfParamaters,
getNumberOfRequiredParameters, getParameters, and invoke.
Pages:
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120