Cannot access %s constant %s::%s
Description
Class constants have visibility, which restrict access to the defining class (private), or the class and its children (protected).
Example
<?php
class X {
private const A = 1;
}
echo X::A;
?>
Literal Examples
- Cannot access private constant X::A
Alternatives
- Relax the visibility constraint to
protectedorpublicto make the constant available to the calling context. - Create a method to access the value of the constant.
- Extends the class and change the visibility level of the constant.
Related error messages
In previous PHP versions, this error message used to be :ref:cannot-access-%s-const-%s::%s.