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";

preferences:
31.91 ms | 402 KiB | 5 Q