<?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.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- 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.33
- 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:
158.08 ms | 402 KiB | 178 Q