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

isset() is a function that determines if a variable is declared and is different than null.

isset() is also related to the magic method __isset(), which is used to determine if a property in an object exists or not.

isset() has an error suppression feature, that masks various errors, such as undefined offset or undefined variables. Some other errors, like an invalid type as offset, are still reported.

isset() may be compared to array_key_exists() to check if an index exists in an array. As a micro-optimisation, it is faster than the function.

<?php

    $var = 'something';
    
    if (isset($var)) {
        echo 'The variable $var contains '.$var;
    } else {
        echo 'No such variable as $var';
    }

?>

Documentation

See Also