3v4l.org

run code in 300+ PHP versions simultaneously
<?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 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1
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.0.5, 5.1.0 - 5.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
233.08 ms | 401 KiB | 288 Q