什么值会触发 Null Coalesce 运算符??传入 php 7?

What values trigger the Null Coalesce Operator ?? passing in php 7?

我对空合并运算符(?? 运算符)在 PHP 7 中出现的可能性感到兴奋。但是,我并不了解所有情况。

以下情况我的结果是什么?

function NC($x){
    $y = array();
    $y['test'] = $x;
    $returnThis = $y['test'] ?? "Foo";
    return $returnThis;
}

echo(NC(NULL)); // I know this will return "Foo".
/* But I have no clue about what these will return. */
echo(NC(0));
echo(NC(-1));
echo(NC(""));
echo(NC(array()));

案例:

NC(NULL); // This returns "foo".
NC(0); // Returns 0
NC(-1); // Returns -1
NC(""); // Returns ""
NC(array()); // Returns empty array

与将某些值等同于 null 的其他情况不同,null 运算符不会。它为 null,并且只有 null 才会触发替换。