Annotation of embedaddon/php/ext/reflection/tests/ReflectionParameter_003.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: ReflectionParameter class - isOptional, isDefaultValueAvailable and getDefaultValue methods.
3: --CREDITS--
4: Robin Fernandes <robinf@php.net>
5: Steve Seear <stevseea@php.net>
6: --FILE--
7: <?php
8:
9: class ReflectTestClass {
10: public static function staticMethod($paramOne, $anotherParam = "bob",
11: &$thirdParam = "jack", $arrayParam = array('one')) {
12: echo "hello from test\n";
13: echo "third is $thirdParam\n";
14: return ++$theIncrement;
15: }
16:
17: }
18:
19: $jane = "jane";
20: ReflectTestClass::staticMethod("bob", "jack");
21:
22: $refMethod = new ReflectionMethod('ReflectTestClass', 'staticMethod');
23: $refParameters = $refMethod->getParameters();
24:
25: echo "parameter names from staticMethod method:\n\n";
26: foreach($refParameters as $parameter) {
27: var_dump($parameter);
28: if($parameter->isOptional()) {
29: echo "this parameter is optional\n";
30: } else {
31: echo "this parameter is not optional\n";
32: }
33:
34: if($parameter->isDefaultValueAvailable()) {
35: echo "this parameter has a default value\n";
36: } else {
37: echo "this parameter has no default value\n";
38: }
39:
40: /*
41: $val = 0;
42: try {
43: $val = $parameter->getDefaultValue();
44: var_dump($val);
45: } catch (ReflectionException $e) {
46: print $e->getMessage();
47: echo "\n";
48: }
49: */
50:
51: echo "\n";
52: }
53:
54: ?>
55: --EXPECTF--
56: hello from test
57: third is jack
58:
59: Notice: Undefined variable: theIncrement in %s on line 8
60: parameter names from staticMethod method:
61:
62: object(ReflectionParameter)#%d (1) {
63: ["name"]=>
64: string(8) "paramOne"
65: }
66: this parameter is not optional
67: this parameter has no default value
68:
69: object(ReflectionParameter)#%d (1) {
70: ["name"]=>
71: string(12) "anotherParam"
72: }
73: this parameter is optional
74: this parameter has a default value
75:
76: object(ReflectionParameter)#%d (1) {
77: ["name"]=>
78: string(10) "thirdParam"
79: }
80: this parameter is optional
81: this parameter has a default value
82:
83: object(ReflectionParameter)#%d (1) {
84: ["name"]=>
85: string(10) "arrayParam"
86: }
87: this parameter is optional
88: this parameter has a default value
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>