3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Enum { const FOO = 1; const BAR = 2; const ENUM_VALUES = [ self::FOO, self::BAR ]; public static function isValid($value) : bool { return in_array($value, self::ENUM_VALUES); } } var_dump( Enum::isValid(Enum::FOO), Enum::isValid('baz') );
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3
bool(true) bool(false)
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/5B05R on line 11
Process exited with code 255.

preferences:
48.29 ms | 460 KiB | 5 Q