Null Coalesce
Free Preview
PHP 7+
// This outputs `bar` because `$foo` is not yet defined
echo $foo ?? 'bar';

// You can also check deeply nested objects, which also
// works without errors if objects are undefined
echo $foo->b->c ?? 'baz';

// You can also set default values for iterables to skip
// over loops if variables are null, empty or undefined
foreach ($foo ?? [] as $bar) {
    echo $bar;
PHP <=5
// You must check for the existance of variables with isset()
echo isset($foo) ? $foo : 'bar';

// Each object property must be individually checked
echo (isset($foo) && isset($foo->b) && isset($foo->b->c))
    ? $foo->b->c
    : 'baz';

// Loops can error out if variables aren't explicitly checked
if (isset($foo)) {
    foreach ($foo as $bar) {
        echo $bar;
Want to learn more?

Visit to learn much more about Magento, Laravel, PHP, Javascript, & Docker. logo