这个问题仅供参考。
我想知道是否有办法检查变量是否为 is_set,如果有,请检查它是否设置为 null
基于PHP 类型比较表似乎不可能。
例如,假设我们有以下代码:
<?php
$x = null;
if(isset($x) && is_null($x)){
echo '$x is set to NULL';
}else{
echo '$x was never initialized';
}
echo "\n";
if(isset($y) && is_null($y)){
echo '$y is set to NULL';
}else{
echo '$y was never initialized';
}
echo "\n";
if(is_null($z)){
echo '$z is set to NULL';
}else{
echo '$z was never initialized';
}
?>
我希望页面显示:
$x is set to NULL
$y was never initialized
$z is set to NULL <it should give an E_NOTICE>
但我得到
$x was never initialized
$y was never initialized
$z is set to NULL