3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php namespace Vagabond\Http; class Request{ private $url; private $method; private $sources = []; public function __construct($url, $method){ $this->url = $url; $this->method = $method; } public function setParameterProvider($name, callable $provider){ $this->sources[$name] = $provider; } public function setParameterSource($name, array $data){ $this->sources[$name] = $data; } public function get($source, $name, $default = null){ if (isset($this->sources[$source]) && !is_array($this->sources[$source])){ $this->sources[$source] = call_user_func($this->sources[$source]); } return (isset($this->sources[$source][$name]))?$this->sources[$source][$name]:$default; } public function getUrl(){ return $this->url; } public function getMethod(){ return $this->method; } public static function getPhpDefaultRequest(){ $request = new Request($_SERVER["REQUEST_URI"], $_SERVER["REQUEST_METHOD"]); $request->setParameterSource("get", $_GET); $request->setParameterSource("post", $_POST); $request->setParameterSource("files", $_FILES); $request->setParameterProvider("session", function(){ return $_SESSION; }); $request->setParameterSource("env", $_ENV); $request->setParameterSource("cookie", $_COOKIE); $request->setParameterSource("server", $_SERVER); } } $request = \Vagabond\Http\Request::getPhpDefaultRequest(); $request->setParameterProvider("post", function(){ if ($_SERVER["CONTENT_TYPE"] == "application/json"){ return json_decode(file_get_contents("php://input"), true); } else { return $_POST; } }); $action = $request->get("get", "action"); $username = $request->get("post", "username"); $password = $request->get("post", "password"); ?>
Output for 7.0.0 - 7.1.0
Notice: Undefined index: REQUEST_URI in /in/jsVnM on line 36 Notice: Undefined index: REQUEST_METHOD in /in/jsVnM on line 36 Fatal error: Uncaught Error: Call to a member function setParameterProvider() on null in /in/jsVnM:49 Stack trace: #0 {main} thrown in /in/jsVnM on line 49
Process exited with code 255.
Output for hhvm-3.12.0
Notice: Undefined index: REQUEST_URI in /in/jsVnM on line 36 Notice: Undefined index: REQUEST_METHOD in /in/jsVnM on line 36 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function setParameterProvider() on a non-object (null)' in /in/jsVnM:55 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Notice: Undefined index: REQUEST_URI in /in/jsVnM on line -1 Notice: Undefined index: REQUEST_METHOD in /in/jsVnM on line -1 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function setParameterProvider() on a non-object (null)' in /in/jsVnM:7 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Notice: Undefined index: REQUEST_URI in /in/jsVnM on line 36 Notice: Undefined index: REQUEST_METHOD in /in/jsVnM on line 36 Fatal error: Call to a member function setParameterProvider() on null in /in/jsVnM on line 49
Process exited with code 255.
Output for 5.4.0 - 5.5.37
Notice: Undefined index: REQUEST_URI in /in/jsVnM on line 36 Notice: Undefined index: REQUEST_METHOD in /in/jsVnM on line 36 Fatal error: Call to a member function setParameterProvider() on a non-object in /in/jsVnM on line 49
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/jsVnM on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/jsVnM on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/jsVnM on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/jsVnM on line 3
Process exited with code 255.