Constants Can Be Impossible¶
<?php
enum x : string {
case B = 'b';
const C = 'c';
}
class x2 {
const E = x::B->value;
const F = x::C + [];
}
echo x2::E;
In this code, the constant x2::F is not possible, because adding a string and an array results in a fatal error.
Yet, this is determined at execution time, and only when the constant is used.
Since this constant is never used, its code is never executed, and it doesn’t yield any error. PHP has optimized the error away.
See Also¶
Almost impossible constant [Try me]
PHP Features¶
Last updated: 14 July 2026