This question is merely for information only.
I was wondering if there is a way to check if a variable is_set and if so check if it is set to null
Based on the PHP type comparison tables doesn't seems like that it is possible.
for example, let's say we have this code:
<?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';
}
?>
I would expect the page to show:
$x is set to NULL
$y was never initialized
$z is set to NULL <it should give an E_NOTICE>
but I am getting
$x was never initialized
$y was never initialized
$z is set to NULL