3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Request { private $method; private $path; function __construct($method, $path) { $this->method = $method; $this->path = $path; } function getMethod() { return $this->method; } function getPath() { return $this->path; } } class Router { private $routes = [ 'get' => [], 'post' => [] ]; function get($pattern, callable $handler) { $this->routes['get'][$pattern] = $handler; return $this; } function post($pattern, callable $handler) { $this->routes['post'][$pattern] = $handler; return $this; } function match(Request $request) { $method = strtolower($request->getMethod()); if (!isset($this->routes[$method])) { return false; } $path = $request->getPath(); foreach ($this->routes[$method] as $pattern => $handler) { if ($pattern === $path) { return $handler; } } return false; } } class Dispatcher { private $router; function __construct(Router $router) { $this->router = $router; } function handle(Request $request) { $handler = $this->router->match($request); if (!$handler) { echo "Could not find your resource!\n"; return; } $handler(); } } $router = new Router(); $router->get('foo', function() { echo "GET foo\n"; }); $router->post('bar', function() { echo "POST bar\n"; }); $router->post('toto',function() {écho 'POST toto is thé method';} $dispatcher = new Dispatcher($router); $dispatcher->handle(new Request('GET', 'foo')); $dispatcher->handle(new Request('POST', 'bar')); $dispatcher->handle(new Request('GET', 'qux'));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.1.70.0520.01115.02
7.1.60.0520.01433.03
7.1.50.0790.01732.86
7.1.40.0620.01332.46
7.1.30.0650.01132.54
7.1.20.0580.01432.67
7.1.10.0350.01214.54
7.1.00.0350.01114.62
7.0.200.0440.01114.61
7.0.190.0570.00914.66
7.0.180.0430.01414.17
7.0.170.0480.01014.18
7.0.160.0430.00914.24
7.0.150.0390.01314.16
7.0.140.0410.01214.37
7.0.130.0320.01014.58
7.0.120.0330.01314.49
7.0.110.0320.01214.39
7.0.100.0400.00814.37
7.0.90.0280.01014.27
7.0.80.0340.00714.33
7.0.70.0340.01214.25
7.0.60.0410.01314.14
7.0.50.0350.01114.34
7.0.40.0330.01014.51
7.0.30.0360.01114.50
7.0.20.0280.01214.52
7.0.10.0340.01114.50
7.0.00.0280.01114.42

preferences:
140.42 ms | 1394 KiB | 7 Q