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=heheszki'; // 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 "Witaj " . $request["name"]; } }), ]; // check controllers if(array_key_exists($parsed["path"], $controllers )){ echo $controllers [ $parsed['path'] ]->action($parsedQuery); }
based on PpULW
Output for 7.0.0 - 7.2.0
Array ( [0] => Array ( [scheme] => http [host] => www.testing.com [path] => /login [query] => name=adam&password=heheszki ) [1] => Array ( [name] => adam [password] => heheszki ) ) LOGIN adam, heheszki
Output for 5.5.0 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/hT28Y on line 24
Process exited with code 255.