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
Solutions¶
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.
Static Analysis¶
This error may be tracked down with the following static analysis rules: Classes/UnreachableConstant.