ReflectionMethod_basic3.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. --TEST--
  2. ReflectionMethod class getName(), isInternal() and isUserDefined() methods
  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 "\ngetName():\n";
  10. var_dump($methodInfo->getName());
  11. echo "\nisInternal():\n";
  12. var_dump($methodInfo->isInternal());
  13. echo "\nisUserDefined():\n";
  14. var_dump($methodInfo->isUserDefined());
  15. echo "\n**********************************\n";
  16. }
  17. class TestClass
  18. {
  19. public function foo() {
  20. echo "Called foo()\n";
  21. }
  22. static function stat() {
  23. echo "Called stat()\n";
  24. }
  25. private function priv() {
  26. echo "Called priv()\n";
  27. }
  28. protected function prot() {}
  29. public function __destruct() {}
  30. }
  31. class DerivedClass extends TestClass {}
  32. interface TestInterface {
  33. public function int();
  34. }
  35. reflectMethod("DerivedClass", "foo");
  36. reflectMethod("TestClass", "stat");
  37. reflectMethod("TestClass", "priv");
  38. reflectMethod("TestClass", "prot");
  39. reflectMethod("DerivedClass", "prot");
  40. reflectMethod("TestInterface", "int");
  41. reflectMethod("ReflectionProperty", "__construct");
  42. reflectMethod("TestClass", "__destruct");
  43. ?>
  44. --EXPECT--
  45. **********************************
  46. Reflecting on method DerivedClass::foo()
  47. getName():
  48. string(3) "foo"
  49. isInternal():
  50. bool(false)
  51. isUserDefined():
  52. bool(true)
  53. **********************************
  54. **********************************
  55. Reflecting on method TestClass::stat()
  56. getName():
  57. string(4) "stat"
  58. isInternal():
  59. bool(false)
  60. isUserDefined():
  61. bool(true)
  62. **********************************
  63. **********************************
  64. Reflecting on method TestClass::priv()
  65. getName():
  66. string(4) "priv"
  67. isInternal():
  68. bool(false)
  69. isUserDefined():
  70. bool(true)
  71. **********************************
  72. **********************************
  73. Reflecting on method TestClass::prot()
  74. getName():
  75. string(4) "prot"
  76. isInternal():
  77. bool(false)
  78. isUserDefined():
  79. bool(true)
  80. **********************************
  81. **********************************
  82. Reflecting on method DerivedClass::prot()
  83. getName():
  84. string(4) "prot"
  85. isInternal():
  86. bool(false)
  87. isUserDefined():
  88. bool(true)
  89. **********************************
  90. **********************************
  91. Reflecting on method TestInterface::int()
  92. getName():
  93. string(3) "int"
  94. isInternal():
  95. bool(false)
  96. isUserDefined():
  97. bool(true)
  98. **********************************
  99. **********************************
  100. Reflecting on method ReflectionProperty::__construct()
  101. getName():
  102. string(11) "__construct"
  103. isInternal():
  104. bool(true)
  105. isUserDefined():
  106. bool(false)
  107. **********************************
  108. **********************************
  109. Reflecting on method TestClass::__destruct()
  110. getName():
  111. string(10) "__destruct"
  112. isInternal():
  113. bool(false)
  114. isUserDefined():
  115. bool(true)
  116. **********************************