php-src/tests/classes/constants_visibility_003.phpt
Nikita Popov 7ce531f2c2 Make constant() error handling consistent with plain const lookup
This means we get an Error exception and a much better error
message indicating the root cause (e.g. accessing a private class
constant).
2020-01-10 13:39:56 +01:00

28 lines
500 B
PHP

--TEST--
Class private constant visibility
--FILE--
<?php
class A {
private const privateConst = 'privateConst';
static function staticConstDump() {
var_dump(self::privateConst);
}
function constDump() {
var_dump(self::privateConst);
}
}
A::staticConstDump();
(new A())->constDump();
try {
constant('A::privateConst');
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
string(12) "privateConst"
string(12) "privateConst"
Cannot access private const A::privateConst