PHP has a lot of ways of dealing with variable checking. There are functions that check each type like is_array, is_object or is_bool and there are functions that can be used to check multiple conditions at once. Today we will be dealing with the differences between is_null(), empty() and isset(). First let's explain what each one does.
This function checks only whether a variable has a null value, but it doesn't cover for cases when that variable is undefined or for the cases when a value would evaluate to an empty value.
<?php
$myvar = NULL; is_null($myvar); // This is TRUE
$myvar = 0; is_null($myvar); // This is FALSE
$myvar = FALSE; is_null($myvar); // This is FALSE
$myvar = ''; is_null($myvar); // This is FALSE
is_null($some_undefined_var); //This is also TRUE ... but the script throws a notice because $some_undefined_var doesn't exist
Please note that a null variable is not the same as an undefined variable. Even if they both evaluate to NULL, PHP will through a notice saying: "Notice: Undefined variable: X in..."
This function checks whether a variable is defined (a.k.a exists) within your script. However, isset() also sees variables that have the null value as being not set (if you take the function wording literally).
<?php
$myvar = NULL; isset($myvar); // This is FALSE
$myvar = 0; isset($myvar); // This is TRUE
$myvar = FALSE; isset($myvar); // This is TRUE
$myvar = ''; isset($myvar); // This is TRUE
isset($some_undefined_var); // This is FALSE
This function checks whether a variable evaluates to what PHP sees as a "falsy"(a.k.a empty) value. This being said, a variable is empty if it's undefined, null, false, 0 or an empty string.
To better understand the way empty works... you should think about this function as being the same as: !isset($var) || $var==false.
<?php
$myvar = NULL; empty($myvar); // This is TRUE
$myvar = 0; empty($myvar); // This is TRUE
$myvar = FALSE; empty($myvar); // This is TRUE
$myvar = ''; empty($myvar); // This is TRUE
empty($some_undefined_var); // This is TRUE
To conclude, remember to ALWAYS do your variable checking. This is especially important in PHP which is not a strictly typed programming language so the programmer needs to pay special attention it.