3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // request to php with type $requestedUri = $_SERVER['REQUEST_URI'] = 'http://www.testing.com/login'; $requestedUriWithQuery = $requestedUri . '?name=adam&password=password'; // parse request $parsed = parse_url($requestedUriWithQuery); $parsedQuery = []; parse_str($parsed['query'], $parsedQuery); // check request print_r([ $parsed, $parsedQuery ]); // controllers $controllers = [ '/login' => new class { public function action($request) { return "LOGIN " . implode(", ", $request); } }, '/' => new class { public function action($request) { return "HOME " . implode(", ", $request); } }, ]; // check controllers if(array_key_exists($parsed["path"], $controllers )){ echo $controllers [ $request['path'] ]->action($parsedQuery); }
based on JArCA
Output for 7.0.0 - 7.2.0
Array ( [0] => Array ( [scheme] => http [host] => www.testing.com [path] => /login [query] => name=adam&password=password ) [1] => Array ( [name] => adam [password] => password ) ) Notice: Undefined variable: request in /in/cdAkY on line 43 Notice: Undefined index: in /in/cdAkY on line 43 Fatal error: Uncaught Error: Call to a member function action() on null in /in/cdAkY:43 Stack trace: #0 {main} thrown in /in/cdAkY on line 43
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/cdAkY on line 24
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/cdAkY on line 10
Process exited with code 255.