You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
3.7 KiB

  1. --TEST--
  2. ReflectionMethod class __toString() and export() 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 "__toString():\n";
  10. var_dump($methodInfo->__toString());
  11. echo "\nexport():\n";
  12. var_dump(ReflectionMethod::export($class, $method, true));
  13. echo "\n**********************************\n";
  14. }
  15. class TestClass
  16. {
  17. public function foo() {
  18. echo "Called foo()\n";
  19. }
  20. static function stat() {
  21. echo "Called stat()\n";
  22. }
  23. private function priv() {
  24. echo "Called priv()\n";
  25. }
  26. protected function prot() {}
  27. public function __destruct() {}
  28. }
  29. class DerivedClass extends TestClass {}
  30. interface TestInterface {
  31. public function int();
  32. }
  33. reflectMethod("DerivedClass", "foo");
  34. reflectMethod("TestClass", "stat");
  35. reflectMethod("TestClass", "priv");
  36. reflectMethod("TestClass", "prot");
  37. reflectMethod("DerivedClass", "prot");
  38. reflectMethod("TestInterface", "int");
  39. reflectMethod("ReflectionProperty", "__construct");
  40. reflectMethod("TestClass", "__destruct");
  41. ?>
  42. --EXPECTF--
  43. **********************************
  44. Reflecting on method DerivedClass::foo()
  45. __toString():
  46. string(%d) "Method [ <user, inherits TestClass> public method foo ] {
  47. @@ %s 16 - 18
  48. }
  49. "
  50. export():
  51. string(%d) "Method [ <user, inherits TestClass> public method foo ] {
  52. @@ %s 16 - 18
  53. }
  54. "
  55. **********************************
  56. **********************************
  57. Reflecting on method TestClass::stat()
  58. __toString():
  59. string(%d) "Method [ <user> static public method stat ] {
  60. @@ %s 20 - 22
  61. }
  62. "
  63. export():
  64. string(%d) "Method [ <user> static public method stat ] {
  65. @@ %s 20 - 22
  66. }
  67. "
  68. **********************************
  69. **********************************
  70. Reflecting on method TestClass::priv()
  71. __toString():
  72. string(%d) "Method [ <user> private method priv ] {
  73. @@ %s 24 - 26
  74. }
  75. "
  76. export():
  77. string(%d) "Method [ <user> private method priv ] {
  78. @@ %s 24 - 26
  79. }
  80. "
  81. **********************************
  82. **********************************
  83. Reflecting on method TestClass::prot()
  84. __toString():
  85. string(%d) "Method [ <user> protected method prot ] {
  86. @@ %s 28 - 28
  87. }
  88. "
  89. export():
  90. string(%d) "Method [ <user> protected method prot ] {
  91. @@ %s 28 - 28
  92. }
  93. "
  94. **********************************
  95. **********************************
  96. Reflecting on method DerivedClass::prot()
  97. __toString():
  98. string(%d) "Method [ <user, inherits TestClass> protected method prot ] {
  99. @@ %s 28 - 28
  100. }
  101. "
  102. export():
  103. string(%d) "Method [ <user, inherits TestClass> protected method prot ] {
  104. @@ %s 28 - 28
  105. }
  106. "
  107. **********************************
  108. **********************************
  109. Reflecting on method TestInterface::int()
  110. __toString():
  111. string(%d) "Method [ <user> abstract public method int ] {
  112. @@ %s 36 - 36
  113. }
  114. "
  115. export():
  116. string(%d) "Method [ <user> abstract public method int ] {
  117. @@ %s 36 - 36
  118. }
  119. "
  120. **********************************
  121. **********************************
  122. Reflecting on method ReflectionProperty::__construct()
  123. __toString():
  124. string(%d) "Method [ <internal:Reflection, ctor> public method __construct ] {
  125. - Parameters [1] {
  126. Parameter #0 [ <required> $argument ]
  127. }
  128. }
  129. "
  130. export():
  131. string(%d) "Method [ <internal:Reflection, ctor> public method __construct ] {
  132. - Parameters [1] {
  133. Parameter #0 [ <required> $argument ]
  134. }
  135. }
  136. "
  137. **********************************
  138. **********************************
  139. Reflecting on method TestClass::__destruct()
  140. __toString():
  141. string(%d) "Method [ <user, dtor> public method __destruct ] {
  142. @@ %s 30 - 30
  143. }
  144. "
  145. export():
  146. string(%d) "Method [ <user, dtor> public method __destruct ] {
  147. @@ %s 30 - 30
  148. }
  149. "
  150. **********************************