Entry
Does empty return true or false if the given value is zero (0)?
Are there any changes to the empty() function from PHP3 to PHP4?
Jul 10th, 2003 10:42
Philip Olson, Nathan Wallace, Torben Wilson
This works the same for me in PHP 3 and 4 (recent builds). From the
manual:
int empty(mixed var);
Returns false if var is set and has a non-empty or non-zero value;
true otherwise.
See also isset() and unset().
However, you should note that PHP3 considers a _string_ containing the
zero character to be non-empty, whereas PHP4 considers it to be empty.
i.e. the following snippet outputs "It's empty" under PHP4, but
"It's not empty" under PHP3 (even though '0' evaluates to false under
both versions):
<?php
$test = '0';
if ( empty( $test ) ) {
echo "It's empty<br>\n";
} else {
echo "It's not empty<br>\n";
}
?>
Related manual entries are:
http://www.php.net/empty
http://www.php.net/manual/en/faq.migration4.php
http://www.php.net/manual/en/types.comparisons.php