3v4l.org

run code in 300+ PHP versions simultaneously
<?php $provider = [ 'class Foo { const FOO = +"42"; }; var_dump(Foo::FOO);', // int 42 'const FOO = +"42"; var_dump(FOO);', // int 42 'const FOO = (int)"42"; var_dump(FOO);', // fatal error 'class Foo { const FOO = (int)"42"; }; var_dump(Foo::FOO);', // fatal error ]; foreach ($provider as $code) { echo $code . "\n"; eval($code); echo "\n"; }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.30, 8.0.0 - 8.0.23, 8.1.0 - 8.1.10
class Foo { const FOO = +"42"; }; var_dump(Foo::FOO); int(42) const FOO = +"42"; var_dump(FOO); int(42) const FOO = (int)"42"; var_dump(FOO); Fatal error: Constant expression contains invalid operations in /in/Guplu(12) : eval()'d code on line 1
Process exited with code 255.

preferences:
54.82 ms | 409 KiB | 5 Q