ReflectionMethod_basic2.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. --TEST--
  2. ReflectionMethod class __toString() method
  3. --FILE--
  4. <?php
  5. function reflectMethod($class, $method) {
  6. $methodInfo = new ReflectionMethod($class, $method);
  7. echo "**********************************\n";
  8. echo "Reflecting on method $class::$method()\n\n";
  9. echo "__toString():\n";
  10. var_dump($methodInfo->__toString());
  11. echo "\n**********************************\n";
  12. }
  13. class TestClass
  14. {
  15. public function foo() {
  16. echo "Called foo()\n";
  17. }
  18. static function stat() {
  19. echo "Called stat()\n";
  20. }
  21. private function priv() {
  22. echo "Called priv()\n";
  23. }
  24. protected function prot() {}
  25. public function __destruct() {}
  26. }
  27. class DerivedClass extends TestClass {}
  28. interface TestInterface {
  29. public function int();
  30. }
  31. reflectMethod("DerivedClass", "foo");
  32. reflectMethod("TestClass", "stat");
  33. reflectMethod("TestClass", "priv");
  34. reflectMethod("TestClass", "prot");
  35. reflectMethod("DerivedClass", "prot");
  36. reflectMethod("TestInterface", "int");
  37. reflectMethod("ReflectionProperty", "__construct");
  38. reflectMethod("TestClass", "__destruct");
  39. ?>
  40. --EXPECTF--
  41. **********************************
  42. Reflecting on method DerivedClass::foo()
  43. __toString():
  44. string(%d) "Method [ <user, inherits TestClass> public method foo ] {
  45. @@ %s 14 - 16
  46. }
  47. "
  48. **********************************
  49. **********************************
  50. Reflecting on method TestClass::stat()
  51. __toString():
  52. string(%d) "Method [ <user> static public method stat ] {
  53. @@ %s 18 - 20
  54. }
  55. "
  56. **********************************
  57. **********************************
  58. Reflecting on method TestClass::priv()
  59. __toString():
  60. string(%d) "Method [ <user> private method priv ] {
  61. @@ %s 22 - 24
  62. }
  63. "
  64. **********************************
  65. **********************************
  66. Reflecting on method TestClass::prot()
  67. __toString():
  68. string(%d) "Method [ <user> protected method prot ] {
  69. @@ %s 26 - 26
  70. }
  71. "
  72. **********************************
  73. **********************************
  74. Reflecting on method DerivedClass::prot()
  75. __toString():
  76. string(%d) "Method [ <user, inherits TestClass> protected method prot ] {
  77. @@ %s 26 - 26
  78. }
  79. "
  80. **********************************
  81. **********************************
  82. Reflecting on method TestInterface::int()
  83. __toString():
  84. string(%d) "Method [ <user> abstract public method int ] {
  85. @@ %s 34 - 34
  86. }
  87. "
  88. **********************************
  89. **********************************
  90. Reflecting on method ReflectionProperty::__construct()
  91. __toString():
  92. string(%d) "Method [ <internal:Reflection, ctor> public method __construct ] {
  93. - Parameters [2] {
  94. Parameter #0 [ <required> object|string $class ]
  95. Parameter #1 [ <required> string $property ]
  96. }
  97. }
  98. "
  99. **********************************
  100. **********************************
  101. Reflecting on method TestClass::__destruct()
  102. __toString():
  103. string(%d) "Method [ <user> public method __destruct ] {
  104. @@ %s 28 - 28
  105. }
  106. "
  107. **********************************