ReflectionClass_getProperty_001.phpt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 pubf {
  9. public $a;
  10. static public $s;
  11. }
  12. class subpubf extends pubf {
  13. }
  14. class protf {
  15. protected $a;
  16. static protected $s;
  17. }
  18. class subprotf extends protf {
  19. }
  20. class privf {
  21. private $a;
  22. static protected $s;
  23. }
  24. class subprivf extends privf {
  25. }
  26. $classes = array("pubf", "subpubf", "protf", "subprotf",
  27. "privf", "subprivf");
  28. foreach($classes as $class) {
  29. echo "Reflecting on class $class: \n";
  30. $rc = new ReflectionClass($class);
  31. try {
  32. echo " --> Check for s: ";
  33. var_dump($rc->getProperty("s"));
  34. } catch (exception $e) {
  35. echo $e->getMessage() . "\n";
  36. }
  37. try {
  38. echo " --> Check for a: ";
  39. var_dump($rc->getProperty("a"));
  40. } catch (exception $e) {
  41. echo $e->getMessage() . "\n";
  42. }
  43. try {
  44. echo " --> Check for A: ";
  45. var_dump($rc->getProperty("A"));
  46. } catch (exception $e) {
  47. echo $e->getMessage() . "\n";
  48. }
  49. try {
  50. echo " --> Check for doesNotExist: ";
  51. var_dump($rc->getProperty("doesNotExist"));
  52. } catch (exception $e) {
  53. echo $e->getMessage() . "\n";
  54. }
  55. }
  56. ?>
  57. --EXPECTF--
  58. Reflecting on class pubf:
  59. --> Check for s: object(ReflectionProperty)#%d (2) {
  60. ["name"]=>
  61. string(1) "s"
  62. ["class"]=>
  63. string(4) "pubf"
  64. }
  65. --> Check for a: object(ReflectionProperty)#%d (2) {
  66. ["name"]=>
  67. string(1) "a"
  68. ["class"]=>
  69. string(4) "pubf"
  70. }
  71. --> Check for A: Property pubf::$A does not exist
  72. --> Check for doesNotExist: Property pubf::$doesNotExist does not exist
  73. Reflecting on class subpubf:
  74. --> Check for s: object(ReflectionProperty)#%d (2) {
  75. ["name"]=>
  76. string(1) "s"
  77. ["class"]=>
  78. string(4) "pubf"
  79. }
  80. --> Check for a: object(ReflectionProperty)#%d (2) {
  81. ["name"]=>
  82. string(1) "a"
  83. ["class"]=>
  84. string(4) "pubf"
  85. }
  86. --> Check for A: Property subpubf::$A does not exist
  87. --> Check for doesNotExist: Property subpubf::$doesNotExist does not exist
  88. Reflecting on class protf:
  89. --> Check for s: object(ReflectionProperty)#%d (2) {
  90. ["name"]=>
  91. string(1) "s"
  92. ["class"]=>
  93. string(5) "protf"
  94. }
  95. --> Check for a: object(ReflectionProperty)#%d (2) {
  96. ["name"]=>
  97. string(1) "a"
  98. ["class"]=>
  99. string(5) "protf"
  100. }
  101. --> Check for A: Property protf::$A does not exist
  102. --> Check for doesNotExist: Property protf::$doesNotExist does not exist
  103. Reflecting on class subprotf:
  104. --> Check for s: object(ReflectionProperty)#%d (2) {
  105. ["name"]=>
  106. string(1) "s"
  107. ["class"]=>
  108. string(5) "protf"
  109. }
  110. --> Check for a: object(ReflectionProperty)#%d (2) {
  111. ["name"]=>
  112. string(1) "a"
  113. ["class"]=>
  114. string(5) "protf"
  115. }
  116. --> Check for A: Property subprotf::$A does not exist
  117. --> Check for doesNotExist: Property subprotf::$doesNotExist does not exist
  118. Reflecting on class privf:
  119. --> Check for s: object(ReflectionProperty)#%d (2) {
  120. ["name"]=>
  121. string(1) "s"
  122. ["class"]=>
  123. string(5) "privf"
  124. }
  125. --> Check for a: object(ReflectionProperty)#%d (2) {
  126. ["name"]=>
  127. string(1) "a"
  128. ["class"]=>
  129. string(5) "privf"
  130. }
  131. --> Check for A: Property privf::$A does not exist
  132. --> Check for doesNotExist: Property privf::$doesNotExist does not exist
  133. Reflecting on class subprivf:
  134. --> Check for s: object(ReflectionProperty)#%d (2) {
  135. ["name"]=>
  136. string(1) "s"
  137. ["class"]=>
  138. string(5) "privf"
  139. }
  140. --> Check for a: Property subprivf::$a does not exist
  141. --> Check for A: Property subprivf::$A does not exist
  142. --> Check for doesNotExist: Property subprivf::$doesNotExist does not exist