1--TEST--
2ReflectionClass::getProperty()
3--CREDITS--
4Robin Fernandes <robinf@php.net>
5Steve Seear <stevseea@php.net>
6--FILE--
7<?php
8class A {
9	static public $pubC = "pubC in A";
10	static protected $protC = "protC in A";
11	static private $privC = "privC in A";
12
13	static public $pubA = "pubA in A";
14	static protected $protA = "protA in A";
15	static private $privA = "privA in A";
16}
17
18class B extends A {
19	static public $pubC = "pubC in B";
20	static protected $protC = "protC in B";
21	static private $privC = "privC in B";
22
23	static public $pubB = "pubB in B";
24	static protected $protB = "protB in B";
25	static private $privB = "privB in B";
26}
27
28class C extends B {
29	static public $pubC = "pubC in C";
30	static protected $protC = "protC in C";
31	static private $privC = "privC in C";
32}
33
34class X {
35	static public $pubC = "pubC in X";
36	static protected $protC = "protC in X";
37	static private $privC = "privC in X";
38}
39
40$myC = new C;
41$rc = new ReflectionClass("C");
42
43function showInfo($name) {
44	global $rc, $myC;
45	echo "--- (Reflecting on $name) ---\n";
46	try {
47		$rp = $rc->getProperty($name);
48	} catch (Exception $e) {
49		echo $e->getMessage() . "\n";
50		return;
51	}
52	try {
53		var_dump($rp);
54		var_dump($rp->getValue($myC));
55	} catch (Exception $e) {
56		echo $e->getMessage() . "\n";
57		return;
58	}
59}
60
61
62showInfo("pubA");
63showInfo("protA");
64showInfo("privA");
65
66showInfo("pubB");
67showInfo("protB");
68showInfo("privB");
69
70showInfo("pubC");
71showInfo("protC");
72showInfo("privC");
73showInfo("doesntExist");
74
75showInfo("A::pubC");
76showInfo("A::protC");
77showInfo("A::privC");
78
79showInfo("B::pubC");
80showInfo("B::protC");
81showInfo("B::privC");
82
83showInfo("c::pubC");
84showInfo("c::PUBC");
85showInfo("C::pubC");
86showInfo("C::protC");
87showInfo("C::privC");
88
89showInfo("X::pubC");
90showInfo("X::protC");
91showInfo("X::privC");
92showInfo("X::doesntExist");
93
94showInfo("doesntexist::doesntExist");
95
96?>
97--EXPECTF--
98--- (Reflecting on pubA) ---
99object(ReflectionProperty)#%d (2) {
100  [%u|b%"name"]=>
101  %unicode|string%(4) "pubA"
102  [%u|b%"class"]=>
103  %unicode|string%(1) "A"
104}
105%unicode|string%(9) "pubA in A"
106--- (Reflecting on protA) ---
107object(ReflectionProperty)#%d (2) {
108  [%u|b%"name"]=>
109  %unicode|string%(5) "protA"
110  [%u|b%"class"]=>
111  %unicode|string%(1) "A"
112}
113Cannot access non-public member C::protA
114--- (Reflecting on privA) ---
115Property privA does not exist
116--- (Reflecting on pubB) ---
117object(ReflectionProperty)#%d (2) {
118  [%u|b%"name"]=>
119  %unicode|string%(4) "pubB"
120  [%u|b%"class"]=>
121  %unicode|string%(1) "B"
122}
123%unicode|string%(9) "pubB in B"
124--- (Reflecting on protB) ---
125object(ReflectionProperty)#%d (2) {
126  [%u|b%"name"]=>
127  %unicode|string%(5) "protB"
128  [%u|b%"class"]=>
129  %unicode|string%(1) "B"
130}
131Cannot access non-public member C::protB
132--- (Reflecting on privB) ---
133Property privB does not exist
134--- (Reflecting on pubC) ---
135object(ReflectionProperty)#%d (2) {
136  [%u|b%"name"]=>
137  %unicode|string%(4) "pubC"
138  [%u|b%"class"]=>
139  %unicode|string%(1) "C"
140}
141%unicode|string%(9) "pubC in C"
142--- (Reflecting on protC) ---
143object(ReflectionProperty)#%d (2) {
144  [%u|b%"name"]=>
145  %unicode|string%(5) "protC"
146  [%u|b%"class"]=>
147  %unicode|string%(1) "C"
148}
149Cannot access non-public member C::protC
150--- (Reflecting on privC) ---
151object(ReflectionProperty)#%d (2) {
152  [%u|b%"name"]=>
153  %unicode|string%(5) "privC"
154  [%u|b%"class"]=>
155  %unicode|string%(1) "C"
156}
157Cannot access non-public member C::privC
158--- (Reflecting on doesntExist) ---
159Property doesntExist does not exist
160--- (Reflecting on A::pubC) ---
161object(ReflectionProperty)#%d (2) {
162  [%u|b%"name"]=>
163  %unicode|string%(4) "pubC"
164  [%u|b%"class"]=>
165  %unicode|string%(1) "A"
166}
167%unicode|string%(9) "pubC in A"
168--- (Reflecting on A::protC) ---
169object(ReflectionProperty)#%d (2) {
170  [%u|b%"name"]=>
171  %unicode|string%(5) "protC"
172  [%u|b%"class"]=>
173  %unicode|string%(1) "A"
174}
175Cannot access non-public member A::protC
176--- (Reflecting on A::privC) ---
177object(ReflectionProperty)#%d (2) {
178  [%u|b%"name"]=>
179  %unicode|string%(5) "privC"
180  [%u|b%"class"]=>
181  %unicode|string%(1) "A"
182}
183Cannot access non-public member A::privC
184--- (Reflecting on B::pubC) ---
185object(ReflectionProperty)#%d (2) {
186  [%u|b%"name"]=>
187  %unicode|string%(4) "pubC"
188  [%u|b%"class"]=>
189  %unicode|string%(1) "B"
190}
191%unicode|string%(9) "pubC in B"
192--- (Reflecting on B::protC) ---
193object(ReflectionProperty)#%d (2) {
194  [%u|b%"name"]=>
195  %unicode|string%(5) "protC"
196  [%u|b%"class"]=>
197  %unicode|string%(1) "B"
198}
199Cannot access non-public member B::protC
200--- (Reflecting on B::privC) ---
201object(ReflectionProperty)#%d (2) {
202  [%u|b%"name"]=>
203  %unicode|string%(5) "privC"
204  [%u|b%"class"]=>
205  %unicode|string%(1) "B"
206}
207Cannot access non-public member B::privC
208--- (Reflecting on c::pubC) ---
209object(ReflectionProperty)#%d (2) {
210  [%u|b%"name"]=>
211  %unicode|string%(4) "pubC"
212  [%u|b%"class"]=>
213  %unicode|string%(1) "C"
214}
215%unicode|string%(9) "pubC in C"
216--- (Reflecting on c::PUBC) ---
217Property PUBC does not exist
218--- (Reflecting on C::pubC) ---
219object(ReflectionProperty)#%d (2) {
220  [%u|b%"name"]=>
221  %unicode|string%(4) "pubC"
222  [%u|b%"class"]=>
223  %unicode|string%(1) "C"
224}
225%unicode|string%(9) "pubC in C"
226--- (Reflecting on C::protC) ---
227object(ReflectionProperty)#%d (2) {
228  [%u|b%"name"]=>
229  %unicode|string%(5) "protC"
230  [%u|b%"class"]=>
231  %unicode|string%(1) "C"
232}
233Cannot access non-public member C::protC
234--- (Reflecting on C::privC) ---
235object(ReflectionProperty)#%d (2) {
236  [%u|b%"name"]=>
237  %unicode|string%(5) "privC"
238  [%u|b%"class"]=>
239  %unicode|string%(1) "C"
240}
241Cannot access non-public member C::privC
242--- (Reflecting on X::pubC) ---
243Fully qualified property name X::pubC does not specify a base class of C
244--- (Reflecting on X::protC) ---
245Fully qualified property name X::protC does not specify a base class of C
246--- (Reflecting on X::privC) ---
247Fully qualified property name X::privC does not specify a base class of C
248--- (Reflecting on X::doesntExist) ---
249Fully qualified property name X::doesntExist does not specify a base class of C
250--- (Reflecting on doesntexist::doesntExist) ---
251Class doesntexist does not exist
252