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