Cannot declare self-referencing constant¶
Description¶
A self-referencing constant is a constant that is defined by itself.
This error doesn’t apply to global constants. The global constants are immediately made available, and, for that, they need to be evaluated: this leads to the error Undefined constant A
.
Self-referencing constants are not allowed, contraty to self-referencing acronym, that PHP enjoys.
Example¶
<?php
class X {
const A = x::A + 1;
const B = self::C + 1;
const C = x::B + 1;
}
?>
Solutions¶
Create a distinct constant that can help build this one.
Fix the name of the constant with a distinct one.
Fix the name of the class with a distinct one.