3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Example { public function sayHi () { echo "hi"; } } class Caller { private $_controller, $_action; public function __construct ($cont, $action) { $this->_controller = $cont; $this->_action = $action; } public function __toString() { return (string)$this->_action; } public function run () { $controller = new $this->_controller; if (is_callable(array($controller, $this->_action))) { $controller->$this->_action; } } } $caller = new Caller ('Example', 'sayHi'); $caller->run();

preferences:
46.92 ms | 402 KiB | 5 Q