3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CookieStorage { public function addCookie(Cookie $cookie): void { $encodedCookieValue = $this->encodeCookie($cookie->value); setcookie( $cookie->name, $encodedCookieValue, $cookie->options ); $_COOKIE[$cookie->name] = $encodedCookieValue; } public function getCookie(string $cookieName): ?Cookie { $encodedCookieValue = $_COOKIE[$cookieName] ?? null; if (null === $encodedCookieValue) { return null; } $cookieValue = $this->decodeCookie($encodedCookieValue); return new Cookie($cookieName, $cookieValue); } private function encodeCookie(mixed $value): string { return json_encode($value); } private function decodeCookie(string $value): mixed { return json_decode($value); } } class Cookie { readonly public string $name; readonly public mixed $value; readonly public array $options; public function __construct(string $name, mixed $value, array $options = []) { $this->name = $name; $this->value = $value; if ([] === $options) { $options = [ 'expires' => time() + 60 * 60 * 24 * 30, 'secure' => true, 'httponly' => true, ]; } $this->options = $options; } } $storage = new CookieStorage(); $cookie = new Cookie('test', ['one', 'two']); $storage->addCookie($cookie); var_dump($storage->getCookie('test'));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.2.110.0140.00720.35
8.2.100.0150.01518.93
8.2.90.0270.00918.86
8.2.80.0230.00718.83
8.2.70.0160.00620.64
8.2.60.0240.01218.66
8.2.50.0240.01018.49
8.2.40.0250.00918.73
8.2.30.0130.01018.87
8.2.20.0160.01018.86
8.2.10.0150.01118.82
8.2.00.0200.00418.98
8.1.240.0270.00318.38
8.1.230.0120.01218.75
8.1.220.0150.00418.70
8.1.210.0000.01419.81
8.1.200.0070.01418.55
8.1.190.0110.00418.60
8.1.180.0140.01418.55
8.1.170.0160.00618.64
8.1.160.0200.01018.81
8.1.150.0160.01220.68
8.1.140.0250.00418.54
8.1.130.0140.01018.52
8.1.120.0090.00618.54
8.1.110.0270.00318.64
8.1.100.0160.00018.62
8.1.90.0240.01418.53
8.1.80.0200.01418.54
8.1.70.0180.00918.79
8.1.60.0260.00618.64
8.1.50.0270.00318.52
8.1.40.0190.01118.70
8.1.30.0090.00419.00
8.1.20.0220.00618.54
8.1.10.0240.00918.60
8.1.00.0220.00918.42
8.0.300.0170.01017.82
8.0.290.0130.00317.95
8.0.280.0100.00017.96
8.0.270.0100.00317.80
8.0.260.0120.00317.76
8.0.250.0100.00517.96
8.0.240.0120.00017.88
8.0.230.0060.00318.30
8.0.220.0240.00317.81
8.0.210.0200.00717.80
8.0.200.0150.00017.88
8.0.190.0270.00717.88
8.0.180.0190.00417.91
8.0.170.0130.00017.86
8.0.160.0090.00617.88
8.0.150.0320.00017.87
8.0.140.0080.00617.83
8.0.130.0130.00018.10
8.0.120.0170.00917.85
8.0.110.0100.00518.14
8.0.100.0280.00617.88
8.0.90.0080.00517.83
8.0.80.0100.00617.88
8.0.70.0080.00617.74
8.0.60.0120.00417.73
8.0.50.0260.00917.75
8.0.30.0150.00017.86
8.0.20.0180.00917.78
8.0.10.0140.00717.87

preferences:
33.1 ms | 403 KiB | 5 Q