Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

isset() On Constants

It was not possible to use isset() on a constant. PHP mistook it with an expression, and stopped the execution with a Fatal error.

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.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat