isset() On Constants¶
Until PHP 7.0, it was not possible to use isset() on a constant. PHP mistook it with an expression, and stopped.
Since PHP 7.0, it is possible to use isset() with a constant, in particular with the array syntax or the object syntax. Still, isset() should not be used to check the existence of the constant: rather, there is the native function defined().
PHP code¶
<?php
const X = [1,2,3];
if (isset(X[4])) {
echo 'set';
} else {
echo 'not set';
}
?>
Before¶
PHP Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
After¶
not set
PHP version change¶
This behavior changed in 7.0