From the know your language department: It’s already written in the PHP manual, if we could only read it ;) :
empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.
So if you’re feeling a variable being empty, than this is a false and the opposite to it is a true regardless of the variable being set.
So in code:
$result = isset($var) && $var;
is the same as:
$result = !empty($var);
This means constructs like the following:
$is_ssl = isset($args['ssl']) && $args['ssl'];
must have been written by a coder that loves to type a lot. The other coder who is a bit more lazy did it this way:
$is_ssl = !empty($args['ssl']);
Well, let’s be fair. The first example has the benefit of not making use of a false false (of which a not empty could be considered) but a more straight forward true && true. So the later could be seen as more complex as a single hit.
And to be even more fair, this is about type-juggling. With php you should sit safe in the saddle when it’s about converting types from and to booleans.
Empty and Bool Side by Side
|“” (an empty string)||True||False|
|0 (0 as an integer)||True||False|
|0.0 (0 as a float)||True||False|
|“0″ (0 as a string)||True||False|
|NULL (incl. unset variables)||True||False|
|array() (an empty array)||True||False|
|var $var; (a variable declared, but without a value in a class)||True||False|
|SimpleXML objects created from empty tags||True||False|
Everything else is considered to be boolean true and not empty.