static::" is not allowed in compile-time constants
Description
Class constants are meant to hold a single, fixed value shared identically by the declaring class and every subclass that inherits it. Referencing static:: inside a constant expression would make the value depend on late static binding, i.e. on whichever subclass actually reads it, which contradicts a constant’s fixed nature, so PHP rejects it at compile time.
Example
<?php
class Base {
const A = 1;
const B = static::A * 2;
}
?>
Alternatives
- Use self:: instead if the intent is to always refer to the declaring class’s own member.
- Compute the value in a static method instead of a constant.
Related error messages
- static-“-is-not-allowed-in-compile-time-constants
- static::class-cannot-be-used-for-compile-time-class-name-resolution
- cannot-use-dynamic-class-name-in-constant-expression
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See