3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum CacheHit { case CacheHit; } function foo(string $foo): string|CacheHit { static $data = []; if (isset($data[$foo])) { return CacheHit::CacheHit; } $data[$foo] = true; return $foo; } var_dump(foo('foo')); var_dump(foo('bar')); var_dump(foo('bar'));
Output for 8.1.0 - 8.1.34, 8.2.22 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(3) "foo" string(3) "bar" enum(CacheHit::CacheHit)
Output for 8.0.1 - 8.0.17
Parse error: syntax error, unexpected identifier "CacheHit" in /in/dtnNN on line 3
Process exited with code 255.
Output for 7.4.0 - 7.4.28
Parse error: syntax error, unexpected 'CacheHit' (T_STRING) in /in/dtnNN on line 3
Process exited with code 255.

preferences:
57.51 ms | 929 KiB | 4 Q