1--TEST--
2Reflection and property_exists()
3--FILE--
4<?php
5
6class A
7{
8	public    $a = 1;
9	protected $b = 2;
10	private   $c = 3;
11
12	public    $empty;
13	public    $init = 1;
14
15	function __toString()
16	{
17		return 'obj(' . get_class($this) . ')';
18	}
19
20	static function test($oc, $props)
21	{
22		echo '===' . __CLASS__ . "===\n";
23		foreach($props as $p2) {
24			echo $oc, '::$' , $p2, "\n";
25			var_dump(property_exists($oc, $p2));
26		}
27	}
28}
29
30class B extends A
31{
32	private   $c = 4;
33
34	static function test($oc, $props)
35	{
36		echo '===' . __CLASS__ . "===\n";
37		foreach($props as $p2) {
38			echo $oc, '::$' , $p2, "\n";
39			var_dump(property_exists($oc, $p2));
40		}
41	}
42}
43
44class C extends B
45{
46	private   $d = 5;
47
48	static function test($oc, $props)
49	{
50		echo '===' . __CLASS__ . "===\n";
51		foreach($props as $p2) {
52			echo $oc, '::$' , $p2, "\n";
53			var_dump(property_exists($oc, $p2));
54		}
55	}
56}
57
58$oA = new A;
59$oA->e = 6;
60
61$oC = new C;
62
63$pc = array($oA, 'A', 'B', 'C', $oC);
64$pr = array('a', 'b', 'c', 'd', 'e');
65
66foreach($pc as $p1) {
67	if (is_object($p1)) {
68		$p1->test($p1, $pr);
69	} else {
70		$r = new ReflectionMethod($p1, 'test');
71		$r->invoke(NULL, $p1, $pr);
72	}
73	echo "===GLOBAL===\n";
74	foreach($pr as $p2) {
75		echo $p1, '::$' , $p2, "\n";
76		var_dump(property_exists($p1, $p2));
77	}
78}
79
80echo "===PROBLEMS===\n";
81var_dump(property_exists(NULL, 'empty'));
82var_dump(property_exists(25,'empty'));
83var_dump(property_exists('',''));
84var_dump(property_exists('A',''));
85var_dump(property_exists('A','123'));
86var_dump(property_exists('A','init'));
87var_dump(property_exists('A','empty'));
88var_dump(property_exists(new A, ''));
89var_dump(property_exists(new A, '123'));
90var_dump(property_exists(new A, 'init'));
91var_dump(property_exists(new A, 'empty'));
92?>
93===DONE===
94<?php exit(0); ?>
95--EXPECTF--
96===A===
97obj(A)::$a
98bool(true)
99obj(A)::$b
100bool(true)
101obj(A)::$c
102bool(true)
103obj(A)::$d
104bool(false)
105obj(A)::$e
106bool(true)
107===GLOBAL===
108obj(A)::$a
109bool(true)
110obj(A)::$b
111bool(true)
112obj(A)::$c
113bool(true)
114obj(A)::$d
115bool(false)
116obj(A)::$e
117bool(true)
118===A===
119A::$a
120bool(true)
121A::$b
122bool(true)
123A::$c
124bool(true)
125A::$d
126bool(false)
127A::$e
128bool(false)
129===GLOBAL===
130A::$a
131bool(true)
132A::$b
133bool(true)
134A::$c
135bool(true)
136A::$d
137bool(false)
138A::$e
139bool(false)
140===B===
141B::$a
142bool(true)
143B::$b
144bool(true)
145B::$c
146bool(true)
147B::$d
148bool(false)
149B::$e
150bool(false)
151===GLOBAL===
152B::$a
153bool(true)
154B::$b
155bool(true)
156B::$c
157bool(true)
158B::$d
159bool(false)
160B::$e
161bool(false)
162===C===
163C::$a
164bool(true)
165C::$b
166bool(true)
167C::$c
168bool(false)
169C::$d
170bool(true)
171C::$e
172bool(false)
173===GLOBAL===
174C::$a
175bool(true)
176C::$b
177bool(true)
178C::$c
179bool(false)
180C::$d
181bool(true)
182C::$e
183bool(false)
184===C===
185obj(C)::$a
186bool(true)
187obj(C)::$b
188bool(true)
189obj(C)::$c
190bool(false)
191obj(C)::$d
192bool(true)
193obj(C)::$e
194bool(false)
195===GLOBAL===
196obj(C)::$a
197bool(true)
198obj(C)::$b
199bool(true)
200obj(C)::$c
201bool(false)
202obj(C)::$d
203bool(true)
204obj(C)::$e
205bool(false)
206===PROBLEMS===
207
208Warning: First parameter must either be an object or the name of an existing class in %sproperty_exists.php on line %d
209NULL
210
211Warning: First parameter must either be an object or the name of an existing class in %sproperty_exists.php on line %d
212NULL
213bool(false)
214bool(false)
215bool(false)
216bool(true)
217bool(true)
218bool(false)
219bool(false)
220bool(true)
221bool(true)
222===DONE===
223