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