ReflectionClass_getMethod_001.phpt 4.2 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 doesntExist(): ";
  38. try {
  39. var_dump($rc->getMethod("doesntExist"));
  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. [%u|b%"name"]=>
  49. %unicode|string%(1) "f"
  50. [%u|b%"class"]=>
  51. %unicode|string%(4) "pubf"
  52. }
  53. --> Check for s(): object(ReflectionMethod)#%d (2) {
  54. [%u|b%"name"]=>
  55. %unicode|string%(1) "s"
  56. [%u|b%"class"]=>
  57. %unicode|string%(4) "pubf"
  58. }
  59. --> Check for F(): object(ReflectionMethod)#%d (2) {
  60. [%u|b%"name"]=>
  61. %unicode|string%(1) "f"
  62. [%u|b%"class"]=>
  63. %unicode|string%(4) "pubf"
  64. }
  65. --> Check for doesntExist(): Method doesntExist does not exist
  66. Reflecting on class subpubf:
  67. --> Check for f(): object(ReflectionMethod)#%d (2) {
  68. [%u|b%"name"]=>
  69. %unicode|string%(1) "f"
  70. [%u|b%"class"]=>
  71. %unicode|string%(4) "pubf"
  72. }
  73. --> Check for s(): object(ReflectionMethod)#%d (2) {
  74. [%u|b%"name"]=>
  75. %unicode|string%(1) "s"
  76. [%u|b%"class"]=>
  77. %unicode|string%(4) "pubf"
  78. }
  79. --> Check for F(): object(ReflectionMethod)#%d (2) {
  80. [%u|b%"name"]=>
  81. %unicode|string%(1) "f"
  82. [%u|b%"class"]=>
  83. %unicode|string%(4) "pubf"
  84. }
  85. --> Check for doesntExist(): Method doesntExist does not exist
  86. Reflecting on class protf:
  87. --> Check for f(): object(ReflectionMethod)#%d (2) {
  88. [%u|b%"name"]=>
  89. %unicode|string%(1) "f"
  90. [%u|b%"class"]=>
  91. %unicode|string%(5) "protf"
  92. }
  93. --> Check for s(): object(ReflectionMethod)#%d (2) {
  94. [%u|b%"name"]=>
  95. %unicode|string%(1) "s"
  96. [%u|b%"class"]=>
  97. %unicode|string%(5) "protf"
  98. }
  99. --> Check for F(): object(ReflectionMethod)#%d (2) {
  100. [%u|b%"name"]=>
  101. %unicode|string%(1) "f"
  102. [%u|b%"class"]=>
  103. %unicode|string%(5) "protf"
  104. }
  105. --> Check for doesntExist(): Method doesntExist does not exist
  106. Reflecting on class subprotf:
  107. --> Check for f(): object(ReflectionMethod)#%d (2) {
  108. [%u|b%"name"]=>
  109. %unicode|string%(1) "f"
  110. [%u|b%"class"]=>
  111. %unicode|string%(5) "protf"
  112. }
  113. --> Check for s(): object(ReflectionMethod)#%d (2) {
  114. [%u|b%"name"]=>
  115. %unicode|string%(1) "s"
  116. [%u|b%"class"]=>
  117. %unicode|string%(5) "protf"
  118. }
  119. --> Check for F(): object(ReflectionMethod)#%d (2) {
  120. [%u|b%"name"]=>
  121. %unicode|string%(1) "f"
  122. [%u|b%"class"]=>
  123. %unicode|string%(5) "protf"
  124. }
  125. --> Check for doesntExist(): Method doesntExist does not exist
  126. Reflecting on class privf:
  127. --> Check for f(): object(ReflectionMethod)#%d (2) {
  128. [%u|b%"name"]=>
  129. %unicode|string%(1) "f"
  130. [%u|b%"class"]=>
  131. %unicode|string%(5) "privf"
  132. }
  133. --> Check for s(): object(ReflectionMethod)#%d (2) {
  134. [%u|b%"name"]=>
  135. %unicode|string%(1) "s"
  136. [%u|b%"class"]=>
  137. %unicode|string%(5) "privf"
  138. }
  139. --> Check for F(): object(ReflectionMethod)#%d (2) {
  140. [%u|b%"name"]=>
  141. %unicode|string%(1) "f"
  142. [%u|b%"class"]=>
  143. %unicode|string%(5) "privf"
  144. }
  145. --> Check for doesntExist(): Method doesntExist does not exist
  146. Reflecting on class subprivf:
  147. --> Check for f(): object(ReflectionMethod)#%d (2) {
  148. [%u|b%"name"]=>
  149. %unicode|string%(1) "f"
  150. [%u|b%"class"]=>
  151. %unicode|string%(5) "privf"
  152. }
  153. --> Check for s(): object(ReflectionMethod)#%d (2) {
  154. [%u|b%"name"]=>
  155. %unicode|string%(1) "s"
  156. [%u|b%"class"]=>
  157. %unicode|string%(5) "privf"
  158. }
  159. --> Check for F(): object(ReflectionMethod)#%d (2) {
  160. [%u|b%"name"]=>
  161. %unicode|string%(1) "f"
  162. [%u|b%"class"]=>
  163. %unicode|string%(5) "privf"
  164. }
  165. --> Check for doesntExist(): Method doesntExist does not exist