ReflectionClass_getProperty_004.phpt 5.8 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("doesntExist");
  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::doesntExist");
  78. showInfo("doesntexist::doesntExist");
  79. ?>
  80. --EXPECTF--
  81. --- (Reflecting on pubA) ---
  82. object(ReflectionProperty)#%d (2) {
  83. [%u|b%"name"]=>
  84. %unicode|string%(4) "pubA"
  85. [%u|b%"class"]=>
  86. %unicode|string%(1) "A"
  87. }
  88. %unicode|string%(9) "pubA in A"
  89. --- (Reflecting on protA) ---
  90. object(ReflectionProperty)#%d (2) {
  91. [%u|b%"name"]=>
  92. %unicode|string%(5) "protA"
  93. [%u|b%"class"]=>
  94. %unicode|string%(1) "A"
  95. }
  96. Cannot access non-public member C::protA
  97. --- (Reflecting on privA) ---
  98. Property privA does not exist
  99. --- (Reflecting on pubB) ---
  100. object(ReflectionProperty)#%d (2) {
  101. [%u|b%"name"]=>
  102. %unicode|string%(4) "pubB"
  103. [%u|b%"class"]=>
  104. %unicode|string%(1) "B"
  105. }
  106. %unicode|string%(9) "pubB in B"
  107. --- (Reflecting on protB) ---
  108. object(ReflectionProperty)#%d (2) {
  109. [%u|b%"name"]=>
  110. %unicode|string%(5) "protB"
  111. [%u|b%"class"]=>
  112. %unicode|string%(1) "B"
  113. }
  114. Cannot access non-public member C::protB
  115. --- (Reflecting on privB) ---
  116. Property privB does not exist
  117. --- (Reflecting on pubC) ---
  118. object(ReflectionProperty)#%d (2) {
  119. [%u|b%"name"]=>
  120. %unicode|string%(4) "pubC"
  121. [%u|b%"class"]=>
  122. %unicode|string%(1) "C"
  123. }
  124. %unicode|string%(9) "pubC in C"
  125. --- (Reflecting on protC) ---
  126. object(ReflectionProperty)#%d (2) {
  127. [%u|b%"name"]=>
  128. %unicode|string%(5) "protC"
  129. [%u|b%"class"]=>
  130. %unicode|string%(1) "C"
  131. }
  132. Cannot access non-public member C::protC
  133. --- (Reflecting on privC) ---
  134. object(ReflectionProperty)#%d (2) {
  135. [%u|b%"name"]=>
  136. %unicode|string%(5) "privC"
  137. [%u|b%"class"]=>
  138. %unicode|string%(1) "C"
  139. }
  140. Cannot access non-public member C::privC
  141. --- (Reflecting on doesntExist) ---
  142. Property doesntExist does not exist
  143. --- (Reflecting on A::pubC) ---
  144. object(ReflectionProperty)#%d (2) {
  145. [%u|b%"name"]=>
  146. %unicode|string%(4) "pubC"
  147. [%u|b%"class"]=>
  148. %unicode|string%(1) "A"
  149. }
  150. %unicode|string%(9) "pubC in C"
  151. --- (Reflecting on A::protC) ---
  152. object(ReflectionProperty)#%d (2) {
  153. [%u|b%"name"]=>
  154. %unicode|string%(5) "protC"
  155. [%u|b%"class"]=>
  156. %unicode|string%(1) "A"
  157. }
  158. Cannot access non-public member A::protC
  159. --- (Reflecting on A::privC) ---
  160. object(ReflectionProperty)#%d (2) {
  161. [%u|b%"name"]=>
  162. %unicode|string%(5) "privC"
  163. [%u|b%"class"]=>
  164. %unicode|string%(1) "A"
  165. }
  166. Cannot access non-public member A::privC
  167. --- (Reflecting on B::pubC) ---
  168. object(ReflectionProperty)#%d (2) {
  169. [%u|b%"name"]=>
  170. %unicode|string%(4) "pubC"
  171. [%u|b%"class"]=>
  172. %unicode|string%(1) "B"
  173. }
  174. %unicode|string%(9) "pubC in C"
  175. --- (Reflecting on B::protC) ---
  176. object(ReflectionProperty)#%d (2) {
  177. [%u|b%"name"]=>
  178. %unicode|string%(5) "protC"
  179. [%u|b%"class"]=>
  180. %unicode|string%(1) "B"
  181. }
  182. Cannot access non-public member B::protC
  183. --- (Reflecting on B::privC) ---
  184. object(ReflectionProperty)#%d (2) {
  185. [%u|b%"name"]=>
  186. %unicode|string%(5) "privC"
  187. [%u|b%"class"]=>
  188. %unicode|string%(1) "B"
  189. }
  190. Cannot access non-public member B::privC
  191. --- (Reflecting on c::pubC) ---
  192. object(ReflectionProperty)#%d (2) {
  193. [%u|b%"name"]=>
  194. %unicode|string%(4) "pubC"
  195. [%u|b%"class"]=>
  196. %unicode|string%(1) "C"
  197. }
  198. %unicode|string%(9) "pubC in C"
  199. --- (Reflecting on c::PUBC) ---
  200. Property PUBC does not exist
  201. --- (Reflecting on C::pubC) ---
  202. object(ReflectionProperty)#%d (2) {
  203. [%u|b%"name"]=>
  204. %unicode|string%(4) "pubC"
  205. [%u|b%"class"]=>
  206. %unicode|string%(1) "C"
  207. }
  208. %unicode|string%(9) "pubC in C"
  209. --- (Reflecting on C::protC) ---
  210. object(ReflectionProperty)#%d (2) {
  211. [%u|b%"name"]=>
  212. %unicode|string%(5) "protC"
  213. [%u|b%"class"]=>
  214. %unicode|string%(1) "C"
  215. }
  216. Cannot access non-public member C::protC
  217. --- (Reflecting on C::privC) ---
  218. object(ReflectionProperty)#%d (2) {
  219. [%u|b%"name"]=>
  220. %unicode|string%(5) "privC"
  221. [%u|b%"class"]=>
  222. %unicode|string%(1) "C"
  223. }
  224. Cannot access non-public member C::privC
  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::doesntExist) ---
  232. Fully qualified property name X::doesntExist does not specify a base class of C
  233. --- (Reflecting on doesntexist::doesntExist) ---
  234. Class doesntexist does not exist