PHP 4.0 Bug #8163 Updated: The string "0" tests true as empty()
| From: | hholzgra@php.net | Date: | Fri, 08 Dec 2000 11:15:33 +0000 |
| Subject: | PHP 4.0 Bug #8163 Updated: The string "0" tests true as empty() | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-40544@lists.php.net to get a copy of this message | ||
ID: 8163
Updated by: hholzgra
Reported By: juhl@eisenstein.dk
Status: Bogus
Bug Type: Scripting Engine problem
Assigned To:
Comments:
see also
http://php.net/version4/incompatibilities.php
[...] The String "0" is now considered empty [...]
Previous Comments:
---------------------------------------------------------------------------
[2000-12-08 05:31:59] zak@php.net
empty() is used to test if a variable is set and contains a non-empty, non-zero value. The
behaviour you describe is expected and desired.
---------------------------------------------------------------------------
[2000-12-08 05:24:52] juhl@eisenstein.dk
The script below produce the following oputput:
a is of type string
b is of type string
b is empty
I believe the 'b is empty' part is wrong, as the variable actually contains a string that
is one char long and as such is not empty.
<?php
$a = '1';
$b = '0';
echo 'a is of type '.gettype($a).'<br>';
echo 'b is of type '.gettype($b).'<br>';
if (empty($a)) {
echo 'a is empty<br>';
}
if (empty($b)) {
echo 'b is empty<br>';
}
?>
Best regards,
Jesper Juhl
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=8163