PHP 4.0 Bug #8163 Updated: The string "0" tests true as empty()

From: Date: Fri, 08 Dec 2000 12:30:03 +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-40553@lists.php.net to get a copy of this message
ID: 8163 Updated by: juhl Reported By: juhl@eisenstein.dk Status: Bogus Bug Type: Scripting Engine problem Assigned To: Comments: I am aware that the behaviour is exactely what's documented. But it just seems illogical to me that a string that actually contains a a char (even if that char happens to be "0") is interpreted as empty. Could you please explain why you find that functionality desireable? Maybe my bug report should be moved to feature/change request ??? Best regards, Jesper Juhl juhl@eisenstein.dk Previous Comments: --------------------------------------------------------------------------- [2000-12-08 06:15:33] hholzgra@php.net see also http://php.net/version4/incompatibilities.php [...] The String "0" is now considered empty [...] --------------------------------------------------------------------------- [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

« previous php.dev (#40553) next »