I am working with a newcomer to PHP and he asked me about setting a variable to null and how to check that.  He had found some example or information that showed that setting a varaible equal to null would unset the variable.  So, he was unclear if he could then reliably check if the variable was equal to null.  Having avoided null like the plague in my years of PHP, I was not sure.  So, I mocked up a quick script to see what the states of a variable are in relation to null.

<?php

error_reporting(E_ALL);

$null = null;

if($null == null){
echo "Yes, it is equivilent to null\n";
}

if($null === null){
echo "Yes, it is null\n";
}

if(isset($null)){
echo "Yes, it is set\n";
}

if(empty($null)){
echo "Yes, it is empty\n";
}

?>

The output of this script is:

Yes, it is equivilent to null
Yes, it is null
Yes, it is empty

It should also be noted that without declaring the variable, you will see PHP notices about an undefined variable.  So, there is a slight difference between and unset variable and a variable that has been set to null.