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

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: PHP 4.0 Bug #8163 Updated: The string "0" tests true as empty()
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-40546@lists.php.net to get a copy of this message
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 On 8 Dec 2000, Bug Database wrote: > ID: 8163 > Updated by: zak > Reported By: juhl@eisenstein.dk > Status: Bogus > Bug Type: Scripting Engine problem > Assigned To: > Comments: > > 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. > > Previous Comments: > --------------------------------------------------------------------------- > > [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 (#40546) next »