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 53 var_dump($rp); 54 var_dump($rp->getValue($myC)); 55} 56 57 58showInfo("pubA"); 59showInfo("protA"); 60showInfo("privA"); 61 62showInfo("pubB"); 63showInfo("protB"); 64showInfo("privB"); 65 66showInfo("pubC"); 67showInfo("protC"); 68showInfo("privC"); 69showInfo("doesNotExist"); 70 71showInfo("A::pubC"); 72showInfo("A::protC"); 73showInfo("A::privC"); 74 75showInfo("B::pubC"); 76showInfo("B::protC"); 77showInfo("B::privC"); 78 79showInfo("c::pubC"); 80showInfo("c::PUBC"); 81showInfo("C::pubC"); 82showInfo("C::protC"); 83showInfo("C::privC"); 84 85showInfo("X::pubC"); 86showInfo("X::protC"); 87showInfo("X::privC"); 88showInfo("X::doesNotExist"); 89 90showInfo("doesNotexist::doesNotExist"); 91 92?> 93--EXPECTF-- 94--- (Reflecting on pubA) --- 95object(ReflectionProperty)#%d (2) { 96 ["name"]=> 97 string(4) "pubA" 98 ["class"]=> 99 string(1) "A" 100} 101string(9) "pubA in A" 102--- (Reflecting on protA) --- 103object(ReflectionProperty)#%d (2) { 104 ["name"]=> 105 string(5) "protA" 106 ["class"]=> 107 string(1) "A" 108} 109string(10) "protA in A" 110--- (Reflecting on privA) --- 111Property C::$privA does not exist 112--- (Reflecting on pubB) --- 113object(ReflectionProperty)#%d (2) { 114 ["name"]=> 115 string(4) "pubB" 116 ["class"]=> 117 string(1) "B" 118} 119string(9) "pubB in B" 120--- (Reflecting on protB) --- 121object(ReflectionProperty)#%d (2) { 122 ["name"]=> 123 string(5) "protB" 124 ["class"]=> 125 string(1) "B" 126} 127string(10) "protB in B" 128--- (Reflecting on privB) --- 129Property C::$privB does not exist 130--- (Reflecting on pubC) --- 131object(ReflectionProperty)#%d (2) { 132 ["name"]=> 133 string(4) "pubC" 134 ["class"]=> 135 string(1) "C" 136} 137string(9) "pubC in C" 138--- (Reflecting on protC) --- 139object(ReflectionProperty)#%d (2) { 140 ["name"]=> 141 string(5) "protC" 142 ["class"]=> 143 string(1) "C" 144} 145string(10) "protC in C" 146--- (Reflecting on privC) --- 147object(ReflectionProperty)#%d (2) { 148 ["name"]=> 149 string(5) "privC" 150 ["class"]=> 151 string(1) "C" 152} 153string(10) "privC in C" 154--- (Reflecting on doesNotExist) --- 155Property C::$doesNotExist does not exist 156--- (Reflecting on A::pubC) --- 157object(ReflectionProperty)#%d (2) { 158 ["name"]=> 159 string(4) "pubC" 160 ["class"]=> 161 string(1) "A" 162} 163string(9) "pubC in A" 164--- (Reflecting on A::protC) --- 165object(ReflectionProperty)#%d (2) { 166 ["name"]=> 167 string(5) "protC" 168 ["class"]=> 169 string(1) "A" 170} 171string(10) "protC in A" 172--- (Reflecting on A::privC) --- 173object(ReflectionProperty)#%d (2) { 174 ["name"]=> 175 string(5) "privC" 176 ["class"]=> 177 string(1) "A" 178} 179string(10) "privC in A" 180--- (Reflecting on B::pubC) --- 181object(ReflectionProperty)#%d (2) { 182 ["name"]=> 183 string(4) "pubC" 184 ["class"]=> 185 string(1) "B" 186} 187string(9) "pubC in B" 188--- (Reflecting on B::protC) --- 189object(ReflectionProperty)#%d (2) { 190 ["name"]=> 191 string(5) "protC" 192 ["class"]=> 193 string(1) "B" 194} 195string(10) "protC in B" 196--- (Reflecting on B::privC) --- 197object(ReflectionProperty)#%d (2) { 198 ["name"]=> 199 string(5) "privC" 200 ["class"]=> 201 string(1) "B" 202} 203string(10) "privC in B" 204--- (Reflecting on c::pubC) --- 205object(ReflectionProperty)#%d (2) { 206 ["name"]=> 207 string(4) "pubC" 208 ["class"]=> 209 string(1) "C" 210} 211string(9) "pubC in C" 212--- (Reflecting on c::PUBC) --- 213Property C::$PUBC does not exist 214--- (Reflecting on C::pubC) --- 215object(ReflectionProperty)#%d (2) { 216 ["name"]=> 217 string(4) "pubC" 218 ["class"]=> 219 string(1) "C" 220} 221string(9) "pubC in C" 222--- (Reflecting on C::protC) --- 223object(ReflectionProperty)#%d (2) { 224 ["name"]=> 225 string(5) "protC" 226 ["class"]=> 227 string(1) "C" 228} 229string(10) "protC in C" 230--- (Reflecting on C::privC) --- 231object(ReflectionProperty)#%d (2) { 232 ["name"]=> 233 string(5) "privC" 234 ["class"]=> 235 string(1) "C" 236} 237string(10) "privC in C" 238--- (Reflecting on X::pubC) --- 239Fully qualified property name X::$pubC does not specify a base class of C 240--- (Reflecting on X::protC) --- 241Fully qualified property name X::$protC does not specify a base class of C 242--- (Reflecting on X::privC) --- 243Fully qualified property name X::$privC does not specify a base class of C 244--- (Reflecting on X::doesNotExist) --- 245Fully qualified property name X::$doesNotExist does not specify a base class of C 246--- (Reflecting on doesNotexist::doesNotExist) --- 247Class "doesnotexist" does not exist 248