3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Cookie implements ArrayAccess { public function offsetSet($offset, $value) { setcookie($offset, $value); } public function offsetGet($offset) { return $_COOKIE[$offset]; } public function offsetUnset($offset) { setcookie($offset, null, time()-1); } public function offsetExists($offset) { return isset($_COOKIE[$offset]); } } $cookie = new Cookie; // 读取Cookie print $cookie["username"]; // 写入Cookie $cookie["passwd"] = "123abc";
Output for 5.3.0 - 7.1.0
Notice: Undefined index: username in /in/XHZIl on line 8 Warning: Cannot modify header information - headers already sent by (output started at /in/XHZIl:8) in /in/XHZIl on line 4
Output for 5.2.3 - 5.2.17
Notice: Undefined index: username in /in/XHZIl on line 8 Warning: Cannot modify header information - headers already sent by (output started at /in/XHZIl:8) in /in/XHZIl on line 4
Output for 5.0.0 - 5.2.2
Notice: Undefined index: username in /in/XHZIl on line 8
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/XHZIl on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/XHZIl on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/XHZIl on line 2
Process exited with code 255.