3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class PhpNw15Conference { public function listSpeakers() { return array('James Mallison', 'Some other speaker'); } } /** * Class Controller */ class Controller { /** * @return array */ public function __construct(PhpNw15Conference $conference) { $this->conference = $conference; } public function speakersAction() { return $this->conference->listSpeakers(); } } /** Controller Resolver **/ $controller = 'Controller'; // Retrieved from URL + YAML config $action = 'speakersAction'; // Retrieved from URL + Yaml config $params = array(); // Retrieved from GET / POST parameters $reflector = new \ReflectionClass('Controller'); foreach ($reflector->getConstructor()->getParameters() as $parameter) { $className = $parameter->getName(); $parameter = new $className; } echo (new $controller($parameter))->$action($params);
based on YrjfK
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Class 'conference' not found in /in/1Y4Qu:40 Stack trace: #0 {main} thrown in /in/1Y4Qu on line 40
Process exited with code 255.
Output for 5.4.2 - 5.6.21
Fatal error: Class 'conference' not found in /in/1Y4Qu on line 40
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/1Y4Qu on line 43
Process exited with code 255.