3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Router { private $routeList; public function addRoute($url, $callback){ $this->routeList[$url] = $callback; } public function route($url){ $this->routeList[$url]->call($this, $url); } } class HomeController { public function __construct($router){ $router->addRoute('/', function(){ return $this->doHomePage(); }); } private function doHomePage(){ $quote = $this->getRandomQuote(); return new Response('home.html', ['quote' => $quote]); } private function getRandomQuote(){ $quotes = ['You can do anything, but not everything.—David Allen', ' The richest man is not he who has the most, but he who needs the least. —Unknown Author','You miss 100 percent of the shots you never take.—Wayne Gretzky']; return $quotes[array_rand($quotes)]; } } class Response { public function __construct($template, $data){ } } $router = new Router(); $controller = new HomeController($router); $router->route('/');
Output for 7.0.0 - 7.0.25, 7.1.0 - 7.1.33, 7.2.17 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
Fatal error: Uncaught Error: Call to undefined method Router::doHomePage() in /in/WlsRe:17 Stack trace: #0 [internal function]: Router->{closure}('/') #1 /in/WlsRe(10): Closure->call(Object(Router), '/') #2 /in/WlsRe(41): Router->route('/') #3 {main} thrown in /in/WlsRe on line 17
Process exited with code 255.

preferences:
94.34 ms | 402 KiB | 75 Q