5 const SOME_CONSTANT
= "some string";
7 #===============================================================================
10 class State
{ static $staticX = 4; }
13 * This is f's doc comment.
15 function f($a, &$b, $c=null, $d=array(1, 2, SOME_CONSTANT
)) {
22 $rf = new ReflectionFunction("f");
24 print "--- getDocComment(\"f\") ---\n";
25 var_dump($rf->getDocComment());
28 print "--- getStartLine(\"f\") ---\n";
29 var_dump($rf->getStartLine());
32 print "--- getEndLine(\"f\") ---\n";
33 var_dump($rf->getEndLine());
36 print "--- getFileName(\"f\") ---\n";
37 var_dump($rf->getFileName());
40 print "--- getName(\"f\") ---\n";
41 var_dump($rf->getName());
44 print "--- getNumberOfParameters(\"f\") ---\n";
45 var_dump($rf->getNumberOfParameters());
48 print "--- getNumberOfRequiredParameters(\"f\") ---\n";
49 var_dump($rf->getNumberOfRequiredParameters());
52 print "--- getParameters(\"f\") ---\n";
53 var_dump($rf->getParameters());
60 print "--- isInternal(\"f\") ---\n";
61 var_dump($rf->isInternal());
64 print "--- isUserDefined(\"f\") ---\n";
65 var_dump($rf->isUserDefined());
68 print "--- export(\"f\") ---\n";
69 var_dump(ReflectionFunction
::export('f', true));
86 * This is g's doc comment.
88 function g($a=null, $b=array(1, 2, 3), $c=SOME_CONSTANT
) {
89 print "In g($a, $b, $c)\n";
92 $rg = new ReflectionFunction("g");
94 print "--- invoke(\"g\") ---\n";
95 var_dump($rg->invoke("a", "b"));
96 var_dump($rg->invoke("a", "b"));
99 print "--- export(\"g\") ---\n";
100 var_dump(ReflectionFunction
::export('g', true));
103 #===============================================================================
107 public function methH();
110 public function methI();
113 public function methJ();
115 interface K
extends I
, J
{
116 public function methK();
120 class A
implements H
{
121 public function methH() {}
122 protected function methA() {}
125 * This is B's doc comment.
127 class B
extends A
implements I
, K
{
131 static $s1 = "hello";
137 static public function smethB0() {}
138 static private function smethB1() {}
139 public function methI() {}
140 public function methJ() {}
141 public function methK() {}
142 private function methB() {}
146 $rb = new ReflectionClass("B");
148 print "--- export() ---\n";
149 var_dump(ReflectionClass
::export('B', true));
152 print "--- getConstant() ---\n";
153 var_dump($rb->getConstant('C0'));
154 var_dump($rb->getConstant('C1'));
157 print "--- getConstants() ---\n";
158 var_dump($rb->getConstants());
161 print "--- getConstructor() ---\n";
162 var_dump($rb->getConstructor());
165 print "--- getDocComment() ---\n";
166 var_dump($rb->getDocComment());
169 print "--- getStartLine() ---\n";
170 var_dump($rb->getStartLine());
173 print "--- getEndLine() ---\n";
174 var_dump($rb->getEndLine());
177 print "--- getFileName() ---\n";
178 var_dump($rb->getFileName());
181 print "--- getInterfaceNames() ---\n";
182 var_dump($rb->getInterfaceNames());
185 print "--- getInterfaces() ---\n";
193 print "--- getMethod() ---\n";
196 print "--- getMethods() ---\n";
204 print "--- getModifiers() ---\n";
205 var_dump($rb->getModifiers());
208 print "--- getName() ---\n";
209 var_dump($rb->getName());
212 print "--- getParentClass() ---\n";
213 var_dump($rb->getParentClass());
214 var_dump($rb->getParentClass()->getName());
217 print "--- getProperties() ---\n";
225 print "--- getProperty() ---\n";
228 $rb->getProperty('p0')
233 print "--- getStaticProperties() ---\n";
236 $rb->getStaticProperties()
241 print "--- setStaticPropertyValue() ---\n";
242 var_dump($rb->setStaticPropertyValue('s0', 'new value for s0'));
245 print "--- getStaticPropertyValue() ---\n";
246 var_dump($rb->getStaticPropertyValue('s0'));
247 var_dump($rb->getStaticPropertyValue('s2'));
250 print "--- hasConstant() ---\n";
251 var_dump($rb->hasConstant('C0'));
252 var_dump($rb->hasConstant('C4'));
255 print "--- hasMethod() ---\n";
256 var_dump($rb->hasMethod('methB'));
257 var_dump($rb->hasMethod('methX'));
260 print "--- hasProperty() ---\n";
261 var_dump($rb->hasProperty('p0'));
262 var_dump($rb->hasProperty('p4'));
265 print "--- implementsInterface() ---\n";
266 var_dump($rb->implementsInterface('H'));
267 var_dump($rb->implementsInterface('L'));
270 print "--- isAbstract() ---\n";
271 var_dump($rb->isAbstract());
274 print "--- isFinal() ---\n";
275 var_dump($rb->isFinal());
278 print "--- isInstance() ---\n";
279 var_dump($rb->isInstance(new B
));
280 var_dump($rb->isInstance(new C
));
283 print "--- isInstantiable() ---\n";
284 var_dump($rb->isInstantiable());
287 print "--- isInterface() ---\n";
288 var_dump($rb->isInterface());
291 print "--- isInternal() ---\n";
292 var_dump($rb->isInternal());
295 print "--- isIterateable() ---\n";
296 var_dump($rb->isIterateable());
299 print "--- isSubclassOf() ---\n";
300 var_dump($rb->isSubclassOf('A'));
301 var_dump($rb->isSubclassOf('C'));
304 print "--- isUserDefined() ---\n";
305 var_dump($rb->isUserDefined());
308 print "--- newInstance() ---\n";
309 var_dump($rb->newInstance());
312 print "--- newInstanceArgs() ---\n";
313 var_dump($rb->newInstanceArgs());
316 print "--- get_defined_functions() ---\n";
317 $a = get_defined_functions()["user"];
321 print "--- get_defined_constants() ---\n";
322 $a = get_defined_constants();
323 print "SOME_CONSTANT: " . $a["SOME_CONSTANT"] . "\n";
324 if (isset($a["ANOTHER_CONSTANT"])) {
325 print "ANOTHER_CONSTANT: ".$a["ANOTHER_CONSTANT"]."\n";
327 const ANOTHER_CONSTANT
="some other string";
328 $a = get_defined_constants();
329 print "SOME_CONSTANT: " . $a["SOME_CONSTANT"] . "\n";
330 print "ANOTHER_CONSTANT: ".$a["ANOTHER_CONSTANT"]."\n";
332 print "--- get_declared_classes() ---\n";
333 $a = array_flip(get_declared_classes());
334 $classes = array("A", "B", "C");
335 foreach ($classes as $c) {
337 print "Found class $c\n";
339 print "Missing class $c\n";
343 print "--- get_declared_interfaces() ---\n";
344 $a = array_flip(get_declared_interfaces());
345 $interfaces = array("H", "I", "J", "K", "L");
346 foreach ($interfaces as $i) {
348 print "Found interface $i\n";
350 print "Missing interface $i\n";