MIR0012
TraitConstantAccessedDirectly
A trait constant is accessed directly (e.g., MyTrait::CONST_NAME). In PHP, trait constants cannot be accessed directly; they must be accessed through a class that uses the trait.
Example
Section titled “Example”<?phptrait MyTrait { const NAME = 'trait';}
class MyClass { use MyTrait;}
// Error: accessing trait constant directlyecho MyTrait::NAME;How to fix
Section titled “How to fix”Access the constant through a class that uses the trait:
<?phptrait MyTrait { const NAME = 'trait';}
class MyClass { use MyTrait;}
// Correct: access through the classecho MyClass::NAME;