3v4l.org

run code in 300+ PHP versions simultaneously
<?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); }
Output for 8.3.0 - 8.3.4
Array ( [0] => Array ( [scheme] => http [host] => www.testing.com [path] => /login [query] => name=adam&password=password ) [1] => Array ( [name] => adam [password] => password ) ) Warning: Undefined variable $request in /in/cdAkY on line 43 Warning: Trying to access array offset on null in /in/cdAkY on line 43 Warning: Undefined array key "" 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 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17
Array ( [0] => Array ( [scheme] => http [host] => www.testing.com [path] => /login [query] => name=adam&password=password ) [1] => Array ( [name] => adam [password] => password ) ) Warning: Undefined variable $request in /in/cdAkY on line 43 Warning: Trying to access array offset on value of type null in /in/cdAkY on line 43 Warning: Undefined array key "" 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 7.4.0 - 7.4.33
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: Trying to access array offset on value of type null 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 7.3.32 - 7.3.33
Array ( [0] => Array ( [scheme] => http [host] => www.testing.com [path] => /login [query] => name=adam&password=password ) [1] => Array ( [name] => adam [password] => password ) ) 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 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
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.5.24 - 5.5.35, 5.6.8 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/cdAkY on line 24
Process exited with code 255.

preferences:
186.21 ms | 401 KiB | 194 Q