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