Downsides
There is no way to ensure that any one of variables will exist at any given point.
/**
* There are downsides of the way PHP handles variables.
* There is no way to ensure that any one of them ...
* will exist at any given point
*
* isset() will return TRUE if a variable ...
* exists and has a value other than NULL
*
* empty() will returns TRUE if a variable ...
* has a empty and zero value ("", 0, NULL)
*/
if(isset($a) && $a != "")
echo 1;
if(!empty($a)) // better
echo 1;
Check
Empty() checks only variables as anything else will result in a parse error.
/**
* isset() - determine if a variable is set and is not NULL
* empty() - determine whether a variable is empty
*/
$a = 1;
$b = 0;
$c = "";
$d = null;
echo isset($a) ? 1 : 0; // 1
echo isset($b) ? 2 : 0; // 2
echo isset($c) ? 3 : 0; // 3
echo isset($d) ? 4 : 0; // 0
echo empty("") ? 5 : 0; // 5
echo empty(0) ? 6 : 0; // 6
echo empty("0") ? 7 : 0; // 7
echo empty(NULL) ? 8 : 0; // 8
echo empty(false) ? 9 : 0; // 9
echo empty(array()) ? 1 : 0; // 1
Last update: 357 days ago