ReflectionClass_getProperty_003.phpt 5.2 KB

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