3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait DeserializableEnum { public static function from($value) { return self::{$value}; } public static function tryFrom($value) { try { return self::from($value); } catch (Throwable) { return null; } } } enum Foo { use DeserializableEnum; case one; } var_dump( Foo::from("one"), Foo::tryFrom("aaa") );
Output for 8.3.5 - 8.3.25, 8.4.8 - 8.4.13
enum(Foo::one) NULL
Output for 8.2.29
Parse error: syntax error, unexpected token ";", expecting "(" in /in/DoXJo on line 5
Process exited with code 255.

preferences:
57.01 ms | 406 KiB | 5 Q