Annotation of embedaddon/php/ext/reflection/tests/parameters_002.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: ReflectionParameter::getClass(), getDeclaringClass(), getDeclaringFunction()
3: --FILE--
4: <?php
5:
6: function test($nix, Array $ar, &$ref, stdClass $std, NonExistingClass $na, stdClass &$opt = NULL, $def = "FooBar")
7: {
8: }
9:
10: class test
11: {
12: function test($nix, Array $ar, &$ref, stdClass $std, NonExistingClass $na, stdClass $opt = NULL, $def = "FooBar")
13: {
14: }
15: }
16:
17: function check_params_decl_func($r, $f)
18: {
19: $c = $r->$f();
20: echo $f . ': ' . ($c ? ($c instanceof ReflectionMethod ? $c->class . '::' : '') . $c->name : 'NULL') . "()\n";
21: }
22:
23: function check_params_decl_class($r, $f)
24: {
25: $c = $r->$f();
26: echo $f . ': ' . ($c ? $c->name : 'NULL') . "\n";
27: }
28:
29: function check_params_func($r, $f)
30: {
31: echo $f . ': ';
32: $v = $r->$f();
33: var_dump($v);
34: }
35:
36: function check_params($r)
37: {
38: echo "#####" . ($r instanceof ReflectionMethod ? $r->class . '::' : '') . $r->name . "()#####\n";
39: $i = 0;
40: foreach($r->getParameters() as $p)
41: {
42: echo "===" . $i . "===\n";
43: $i++;
44: check_params_func($p, 'getName');
45: check_params_func($p, 'isPassedByReference');
46: try
47: {
48: check_params_decl_class($p, 'getClass');
49: }
50: catch(ReflectionException $e)
51: {
52: echo $e->getMessage() . "\n";
53: }
54: check_params_decl_class($p, 'getDeclaringClass');
55: // check_params_decl_func($p, 'getDeclaringFunction');
56: check_params_func($p, 'isArray');
57: check_params_func($p, 'allowsNull');
58: check_params_func($p, 'isOptional');
59: check_params_func($p, 'isDefaultValueAvailable');
60: if ($p->isOptional())
61: {
62: check_params_func($p, 'getDefaultValue');
63: }
64: }
65: }
66:
67: check_params(new ReflectionFunction('test'));
68:
69: check_params(new ReflectionMethod('test::test'));
70:
71: ?>
72: ===DONE===
73: <?php exit(0); ?>
74: --EXPECT--
75: #####test()#####
76: ===0===
77: getName: string(3) "nix"
78: isPassedByReference: bool(false)
79: getClass: NULL
80: getDeclaringClass: NULL
81: isArray: bool(false)
82: allowsNull: bool(true)
83: isOptional: bool(false)
84: isDefaultValueAvailable: bool(false)
85: ===1===
86: getName: string(2) "ar"
87: isPassedByReference: bool(false)
88: getClass: NULL
89: getDeclaringClass: NULL
90: isArray: bool(true)
91: allowsNull: bool(false)
92: isOptional: bool(false)
93: isDefaultValueAvailable: bool(false)
94: ===2===
95: getName: string(3) "ref"
96: isPassedByReference: bool(true)
97: getClass: NULL
98: getDeclaringClass: NULL
99: isArray: bool(false)
100: allowsNull: bool(true)
101: isOptional: bool(false)
102: isDefaultValueAvailable: bool(false)
103: ===3===
104: getName: string(3) "std"
105: isPassedByReference: bool(false)
106: getClass: stdClass
107: getDeclaringClass: NULL
108: isArray: bool(false)
109: allowsNull: bool(false)
110: isOptional: bool(false)
111: isDefaultValueAvailable: bool(false)
112: ===4===
113: getName: string(2) "na"
114: isPassedByReference: bool(false)
115: Class NonExistingClass does not exist
116: getDeclaringClass: NULL
117: isArray: bool(false)
118: allowsNull: bool(false)
119: isOptional: bool(false)
120: isDefaultValueAvailable: bool(false)
121: ===5===
122: getName: string(3) "opt"
123: isPassedByReference: bool(true)
124: getClass: stdClass
125: getDeclaringClass: NULL
126: isArray: bool(false)
127: allowsNull: bool(true)
128: isOptional: bool(true)
129: isDefaultValueAvailable: bool(true)
130: getDefaultValue: NULL
131: ===6===
132: getName: string(3) "def"
133: isPassedByReference: bool(false)
134: getClass: NULL
135: getDeclaringClass: NULL
136: isArray: bool(false)
137: allowsNull: bool(true)
138: isOptional: bool(true)
139: isDefaultValueAvailable: bool(true)
140: getDefaultValue: string(6) "FooBar"
141: #####test::test()#####
142: ===0===
143: getName: string(3) "nix"
144: isPassedByReference: bool(false)
145: getClass: NULL
146: getDeclaringClass: test
147: isArray: bool(false)
148: allowsNull: bool(true)
149: isOptional: bool(false)
150: isDefaultValueAvailable: bool(false)
151: ===1===
152: getName: string(2) "ar"
153: isPassedByReference: bool(false)
154: getClass: NULL
155: getDeclaringClass: test
156: isArray: bool(true)
157: allowsNull: bool(false)
158: isOptional: bool(false)
159: isDefaultValueAvailable: bool(false)
160: ===2===
161: getName: string(3) "ref"
162: isPassedByReference: bool(true)
163: getClass: NULL
164: getDeclaringClass: test
165: isArray: bool(false)
166: allowsNull: bool(true)
167: isOptional: bool(false)
168: isDefaultValueAvailable: bool(false)
169: ===3===
170: getName: string(3) "std"
171: isPassedByReference: bool(false)
172: getClass: stdClass
173: getDeclaringClass: test
174: isArray: bool(false)
175: allowsNull: bool(false)
176: isOptional: bool(false)
177: isDefaultValueAvailable: bool(false)
178: ===4===
179: getName: string(2) "na"
180: isPassedByReference: bool(false)
181: Class NonExistingClass does not exist
182: getDeclaringClass: test
183: isArray: bool(false)
184: allowsNull: bool(false)
185: isOptional: bool(false)
186: isDefaultValueAvailable: bool(false)
187: ===5===
188: getName: string(3) "opt"
189: isPassedByReference: bool(false)
190: getClass: stdClass
191: getDeclaringClass: test
192: isArray: bool(false)
193: allowsNull: bool(true)
194: isOptional: bool(true)
195: isDefaultValueAvailable: bool(true)
196: getDefaultValue: NULL
197: ===6===
198: getName: string(3) "def"
199: isPassedByReference: bool(false)
200: getClass: NULL
201: getDeclaringClass: test
202: isArray: bool(false)
203: allowsNull: bool(true)
204: isOptional: bool(true)
205: isDefaultValueAvailable: bool(true)
206: getDefaultValue: string(6) "FooBar"
207: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>