The isset method is used to check if a variable is set, i.e exists and is not set to NULL. But more often than not you find developer making the mistake of using incorrectly, most common mistake is using it to check for empty strings.
$variable = ''; if(isset($variable)) echo "Variable Is Set"; else echo "Not Set";
This will print out “Variable is set”. Obvious to some but not so obvious to others. Like me. 😀
I find that using empty() results in much more predictable results. Empty is much more exhaustive than isset().
empty() will return true on the following values “”, NULL, 0, “0”, FALSE, array()[empty array].
$variable = ''; if(!empty($variable)) echo "Variable Is Set"; else echo "Not Set";
This will print…yep you guessed it “Not Set”
So be careful when checking set values use this two methods interchangeably depending on what you want to do.