3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Controller { public function testAction() { } public static function staticAction() { } public function __call($method, $arguments) { } } $calls = array( array('Controller', 'testAction'), array('Controller', 'staticAction'), array('Controller', 'fooAction'), array(new Controller, 'testAction'), array(new Controller, 'staticAction'), array(new Controller, 'fooAction'), ); foreach($calls as $controller) { $data = array(); try { $r = new ReflectionMethod($controller[0], $controller[1]); $data['controller'] = array( 'class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => $r->getFilename(), 'line' => $r->getStartLine(), ); } catch (ReflectionException $re) { if (is_callable($controller) || method_exists($controller[0], '__call')) { $r = new ReflectionClass($controller[0]); // using __call magic $data['controller'] = array( 'class' => is_object($controller[0]) ? get_class($controller[0]) : $controller[0], 'method' => $controller[1], 'file' => $r->getFilename(), 'line' => $r->getMethod('__call')->getStartLine(), ); } } var_dump($data); }
Output for 5.0.0 - 7.1.0
array(1) { ["controller"]=> array(4) { ["class"]=> string(10) "Controller" ["method"]=> string(10) "testAction" ["file"]=> string(9) "/in/tmC0X" ["line"]=> int(5) } } array(1) { ["controller"]=> array(4) { ["class"]=> string(10) "Controller" ["method"]=> string(12) "staticAction" ["file"]=> string(9) "/in/tmC0X" ["line"]=> int(10) } } array(1) { ["controller"]=> array(4) { ["class"]=> string(10) "Controller" ["method"]=> string(9) "fooAction" ["file"]=> string(9) "/in/tmC0X" ["line"]=> int(15) } } array(1) { ["controller"]=> array(4) { ["class"]=> string(10) "Controller" ["method"]=> string(10) "testAction" ["file"]=> string(9) "/in/tmC0X" ["line"]=> int(5) } } array(1) { ["controller"]=> array(4) { ["class"]=> string(10) "Controller" ["method"]=> string(12) "staticAction" ["file"]=> string(9) "/in/tmC0X" ["line"]=> int(10) } } array(1) { ["controller"]=> array(4) { ["class"]=> string(10) "Controller" ["method"]=> string(9) "fooAction" ["file"]=> string(9) "/in/tmC0X" ["line"]=> int(15) } }
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/tmC0X on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/tmC0X on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/tmC0X on line 5
Process exited with code 255.