ReflectionClass_getMethod_001.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. --TEST--
  2. ReflectionClass::getMethod()
  3. --CREDITS--
  4. Robin Fernandes <robinf@php.net>
  5. Steve Seear <stevseea@php.net>
  6. --FILE--
  7. <?php
  8. class pubf {
  9. public function f() {}
  10. static public function s() {}
  11. }
  12. class subpubf extends pubf {
  13. }
  14. class protf {
  15. protected function f() {}
  16. static protected function s() {}
  17. }
  18. class subprotf extends protf {
  19. }
  20. class privf {
  21. private function f() {}
  22. static private function 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. echo " --> Check for f(): ";
  32. var_dump($rc->getMethod("f"));
  33. echo " --> Check for s(): ";
  34. var_dump($rc->getMethod("s"));
  35. echo " --> Check for F(): ";
  36. var_dump($rc->getMethod("F"));
  37. echo " --> Check for doesNotExist(): ";
  38. try {
  39. var_dump($rc->getMethod("doesNotExist"));
  40. } catch (Exception $e) {
  41. echo $e->getMessage() . "\n";
  42. }
  43. }
  44. ?>
  45. --EXPECTF--
  46. Reflecting on class pubf:
  47. --> Check for f(): object(ReflectionMethod)#%d (2) {
  48. ["name"]=>
  49. string(1) "f"
  50. ["class"]=>
  51. string(4) "pubf"
  52. }
  53. --> Check for s(): object(ReflectionMethod)#%d (2) {
  54. ["name"]=>
  55. string(1) "s"
  56. ["class"]=>
  57. string(4) "pubf"
  58. }
  59. --> Check for F(): object(ReflectionMethod)#%d (2) {
  60. ["name"]=>
  61. string(1) "f"
  62. ["class"]=>
  63. string(4) "pubf"
  64. }
  65. --> Check for doesNotExist(): Method pubf::doesNotExist() does not exist
  66. Reflecting on class subpubf:
  67. --> Check for f(): object(ReflectionMethod)#%d (2) {
  68. ["name"]=>
  69. string(1) "f"
  70. ["class"]=>
  71. string(4) "pubf"
  72. }
  73. --> Check for s(): object(ReflectionMethod)#%d (2) {
  74. ["name"]=>
  75. string(1) "s"
  76. ["class"]=>
  77. string(4) "pubf"
  78. }
  79. --> Check for F(): object(ReflectionMethod)#%d (2) {
  80. ["name"]=>
  81. string(1) "f"
  82. ["class"]=>
  83. string(4) "pubf"
  84. }
  85. --> Check for doesNotExist(): Method subpubf::doesNotExist() does not exist
  86. Reflecting on class protf:
  87. --> Check for f(): object(ReflectionMethod)#%d (2) {
  88. ["name"]=>
  89. string(1) "f"
  90. ["class"]=>
  91. string(5) "protf"
  92. }
  93. --> Check for s(): object(ReflectionMethod)#%d (2) {
  94. ["name"]=>
  95. string(1) "s"
  96. ["class"]=>
  97. string(5) "protf"
  98. }
  99. --> Check for F(): object(ReflectionMethod)#%d (2) {
  100. ["name"]=>
  101. string(1) "f"
  102. ["class"]=>
  103. string(5) "protf"
  104. }
  105. --> Check for doesNotExist(): Method protf::doesNotExist() does not exist
  106. Reflecting on class subprotf:
  107. --> Check for f(): object(ReflectionMethod)#%d (2) {
  108. ["name"]=>
  109. string(1) "f"
  110. ["class"]=>
  111. string(5) "protf"
  112. }
  113. --> Check for s(): object(ReflectionMethod)#%d (2) {
  114. ["name"]=>
  115. string(1) "s"
  116. ["class"]=>
  117. string(5) "protf"
  118. }
  119. --> Check for F(): object(ReflectionMethod)#%d (2) {
  120. ["name"]=>
  121. string(1) "f"
  122. ["class"]=>
  123. string(5) "protf"
  124. }
  125. --> Check for doesNotExist(): Method subprotf::doesNotExist() does not exist
  126. Reflecting on class privf:
  127. --> Check for f(): object(ReflectionMethod)#%d (2) {
  128. ["name"]=>
  129. string(1) "f"
  130. ["class"]=>
  131. string(5) "privf"
  132. }
  133. --> Check for s(): object(ReflectionMethod)#%d (2) {
  134. ["name"]=>
  135. string(1) "s"
  136. ["class"]=>
  137. string(5) "privf"
  138. }
  139. --> Check for F(): object(ReflectionMethod)#%d (2) {
  140. ["name"]=>
  141. string(1) "f"
  142. ["class"]=>
  143. string(5) "privf"
  144. }
  145. --> Check for doesNotExist(): Method privf::doesNotExist() does not exist
  146. Reflecting on class subprivf:
  147. --> Check for f(): object(ReflectionMethod)#%d (2) {
  148. ["name"]=>
  149. string(1) "f"
  150. ["class"]=>
  151. string(5) "privf"
  152. }
  153. --> Check for s(): object(ReflectionMethod)#%d (2) {
  154. ["name"]=>
  155. string(1) "s"
  156. ["class"]=>
  157. string(5) "privf"
  158. }
  159. --> Check for F(): object(ReflectionMethod)#%d (2) {
  160. ["name"]=>
  161. string(1) "f"
  162. ["class"]=>
  163. string(5) "privf"
  164. }
  165. --> Check for doesNotExist(): Method subprivf::doesNotExist() does not exist