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

Solutions

  • Relax the visibility constraint to protected or public to 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.