Cannot access %s const %s::%s
Description
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 more recent PHP versions, this error message is now :ref:cannot-access-%s-constant-%s::%s.