summaryrefslogtreecommitdiff
path: root/ext/reflection/tests/ReflectionClass_getProperty_003.phpt
blob: 61d63362dc7abb7887efa9668b76afc4d491300c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
--TEST--
ReflectionClass::getProperty()
--CREDITS--
Robin Fernandes <robinf@php.net>
Steve Seear <stevseea@php.net>
--FILE--
<?php
class A {
	static public $pubC = "pubC in A";
	static protected $protC = "protC in A";
	static private $privC = "privC in A";

	static public $pubA = "pubA in A";
	static protected $protA = "protA in A";
	static private $privA = "privA in A";
}

class B extends A {
	static public $pubC = "pubC in B";
	static protected $protC = "protC in B";
	static private $privC = "privC in B";

	static public $pubB = "pubB in B";
	static protected $protB = "protB in B";
	static private $privB = "privB in B";
}

class C extends B {
	static public $pubC = "pubC in C";
	static protected $protC = "protC in C";
	static private $privC = "privC in C";
}

class X {
	static public $pubC = "pubC in X";
	static protected $protC = "protC in X";
	static private $privC = "privC in X";
}

$myC = new C;
$rc = new ReflectionClass("C");

function showInfo($name) {
	global $rc, $myC;
	echo "--- (Reflecting on $name) ---\n";
	try {
		$rp = $rc->getProperty($name);
	} catch (Exception $e) {
		echo $e->getMessage() . "\n";
		return;
	}
	try {
		var_dump($rp);
		var_dump($rp->getValue($myC));
	} catch (Exception $e) {
		echo $e->getMessage() . "\n";
		return;
	}
}


showInfo("pubA");
showInfo("protA");
showInfo("privA");

showInfo("pubB");
showInfo("protB");
showInfo("privB");

showInfo("pubC");
showInfo("protC");
showInfo("privC");
showInfo("doesntExist");

showInfo("A::pubC");
showInfo("A::protC");
showInfo("A::privC");

showInfo("B::pubC");
showInfo("B::protC");
showInfo("B::privC");

showInfo("c::pubC");
showInfo("c::PUBC");
showInfo("C::pubC");
showInfo("C::protC");
showInfo("C::privC");

showInfo("X::pubC");
showInfo("X::protC");
showInfo("X::privC");
showInfo("X::doesntExist");

showInfo("doesntexist::doesntExist");

?>
--EXPECTF--
--- (Reflecting on pubA) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(4) "pubA"
  ["class"]=>
  string(1) "A"
}
string(9) "pubA in A"
--- (Reflecting on protA) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "protA"
  ["class"]=>
  string(1) "A"
}
Cannot access non-public member C::$protA
--- (Reflecting on privA) ---
Property privA does not exist
--- (Reflecting on pubB) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(4) "pubB"
  ["class"]=>
  string(1) "B"
}
string(9) "pubB in B"
--- (Reflecting on protB) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "protB"
  ["class"]=>
  string(1) "B"
}
Cannot access non-public member C::$protB
--- (Reflecting on privB) ---
Property privB does not exist
--- (Reflecting on pubC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(4) "pubC"
  ["class"]=>
  string(1) "C"
}
string(9) "pubC in C"
--- (Reflecting on protC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "protC"
  ["class"]=>
  string(1) "C"
}
Cannot access non-public member C::$protC
--- (Reflecting on privC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "privC"
  ["class"]=>
  string(1) "C"
}
Cannot access non-public member C::$privC
--- (Reflecting on doesntExist) ---
Property doesntExist does not exist
--- (Reflecting on A::pubC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(4) "pubC"
  ["class"]=>
  string(1) "A"
}
string(9) "pubC in A"
--- (Reflecting on A::protC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "protC"
  ["class"]=>
  string(1) "A"
}
Cannot access non-public member A::$protC
--- (Reflecting on A::privC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "privC"
  ["class"]=>
  string(1) "A"
}
Cannot access non-public member A::$privC
--- (Reflecting on B::pubC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(4) "pubC"
  ["class"]=>
  string(1) "B"
}
string(9) "pubC in B"
--- (Reflecting on B::protC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "protC"
  ["class"]=>
  string(1) "B"
}
Cannot access non-public member B::$protC
--- (Reflecting on B::privC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "privC"
  ["class"]=>
  string(1) "B"
}
Cannot access non-public member B::$privC
--- (Reflecting on c::pubC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(4) "pubC"
  ["class"]=>
  string(1) "C"
}
string(9) "pubC in C"
--- (Reflecting on c::PUBC) ---
Property PUBC does not exist
--- (Reflecting on C::pubC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(4) "pubC"
  ["class"]=>
  string(1) "C"
}
string(9) "pubC in C"
--- (Reflecting on C::protC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "protC"
  ["class"]=>
  string(1) "C"
}
Cannot access non-public member C::$protC
--- (Reflecting on C::privC) ---
object(ReflectionProperty)#%d (2) {
  ["name"]=>
  string(5) "privC"
  ["class"]=>
  string(1) "C"
}
Cannot access non-public member C::$privC
--- (Reflecting on X::pubC) ---
Fully qualified property name X::pubC does not specify a base class of C
--- (Reflecting on X::protC) ---
Fully qualified property name X::protC does not specify a base class of C
--- (Reflecting on X::privC) ---
Fully qualified property name X::privC does not specify a base class of C
--- (Reflecting on X::doesntExist) ---
Fully qualified property name X::doesntExist does not specify a base class of C
--- (Reflecting on doesntexist::doesntExist) ---
Class doesntexist does not exist