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->getClass(); $parameter = new $className; } echo (new $controller($parameter))->$action($params);
based on 1Y4Qu
Output for 7.0.0 - 7.2.0
Warning: ReflectionClass::__construct() expects exactly 1 parameter, 0 given in /in/IsXcd on line 40 Fatal error: Uncaught TypeError: Argument 1 passed to Controller::__construct() must be an instance of PhpNw15Conference, instance of ReflectionClass given, called in /in/IsXcd on line 43 and defined in /in/IsXcd:19 Stack trace: #0 /in/IsXcd(43): Controller->__construct(Object(ReflectionClass)) #1 {main} thrown in /in/IsXcd on line 19
Process exited with code 255.
Output for 5.4.2 - 5.6.21
Warning: ReflectionClass::__construct() expects exactly 1 parameter, 0 given in /in/IsXcd on line 40 Catchable fatal error: Argument 1 passed to Controller::__construct() must be an instance of PhpNw15Conference, instance of ReflectionClass given, called in /in/IsXcd on line 43 and defined in /in/IsXcd on line 19
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/IsXcd on line 43
Process exited with code 255.