3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); enum MyBackedEnum: int { case One = 1; } try { MyBackedEnum::from('1'); } catch (Throwable $exception) { echo $exception->getMessage(), PHP_EOL; } echo (new ReflectionProperty(MyBackedEnum::class, 'value'))->getType(), PHP_EOL; echo (new ReflectionParameter([MyBackedEnum::class, 'from'], 'value'))->getType(), PHP_EOL; echo (new ReflectionParameter([MyBackedEnum::class, 'tryFrom'], 'value'))->getType(), PHP_EOL;
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.35, 8.3.0 - 8.3.36, 8.4.1 - 8.4.27, 8.5.0 - 8.5.11
MyBackedEnum::from(): Argument #1 ($value) must be of type int, string given int string|int string|int

preferences:
32.19 ms | 1507 KiB | 8 Q