ReflectionClass_getProperty_004.phpt 5.2 KB

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