3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private const C1 = "a"; private const C2 = 'b'; } try { var_dump(constant('Foo::C1')); } catch(Error $e) { echo 'Caught',$e->getMessage(), PHP_EOL; } try{ Foo::C2; } catch(Error $e) { echo 'Caught',$e->getMessage() ,PHP_EOL; }
Output for 8.0.0 - 8.0.23, 8.1.0 - 8.1.10
CaughtCannot access private constant Foo::C1 CaughtCannot access private constant Foo::C2
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 7.4.30
Warning: constant(): Couldn't find constant Foo::C1 in /in/JY1AO on line 9 NULL CaughtCannot access private const Foo::C2
Output for 7.1.0
CaughtCannot access private const Foo::C1 CaughtCannot access private const Foo::C2
Output for 5.6.0 - 5.6.25, 7.0.0 - 7.0.10
Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /in/JY1AO on line 4
Process exited with code 255.

preferences:
45.91 ms | 417 KiB | 6 Q