null is pretty much like any other value in PHP (actually it is also a different data type than string, int, etc.).
However, there is one important difference: isset($var) checks for the existence of var and has a nonzero value.
If you plan to read the variable again before assigning a new value, unset() is the wrong way, but assigning null perfectly fine:
php > $a = null; php > if($a) echo 'x'; php > unset($a); php > if($a) echo 'x'; Notice: Undefined variable: a in php shell code on line 1 php >
As you can see, unset() actually removes the variable, as it never existed, while assigning null sets it to a specific value (and creates a variable if necessary).
A useful example of using null is the default arguments when you want to know if it was provided or not, and empty lines, zero, etc. also valid:
function foo($bar = null) { if($bar === null) { ... } }
Thiefmaster
source share