3v4l.org

run code in 500+ 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.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.13, 8.6.0
enum(Foo::one) NULL
Output for 8.1.34, 8.2.0 - 8.2.36
Parse error: syntax error, unexpected token ";", expecting "(" in /in/DoXJo on line 5
Process exited with code 255.

preferences:
35.81 ms | 1166 KiB | 6 Q