Constant expression contains invalid operations

Description

The Constant expressions are the value of a constant, global or class, that is not a literal value. They are calculated.

Constant expressions allows literals, other constants, and most of the operators. Some elements are forbidden: variables, functions, methods.

Properties are allowed, but only on enumeration’s cases. New and arrays are allowed, and so does the ternary and coalesce operators, leading to possible conditional constants. Magic constant are also OK.

Example

<?php

class x {
     // invalid, because of the usage of the variable
     const X = $a;
}

?>

Solutions

  • Remove the invalid elements or operations.