ID:               50809
 Updated by:       [email protected]
 Reported By:      seanr at webolutionary dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: all
 PHP Version:      5.3.2RC1
 New Comment:

equivalence is not transitive: var_dump("a" == 0, 0 == "b", "a" ==
"b").

empty is simply awkwardly named. empty($v) is simply equivalent to 
!isset($v) || !$v.


Previous Comments:
------------------------------------------------------------------------

[2010-01-20 21:47:56] [email protected]

Anything that when cast to boolean is false is regarded as empty.

Seeing as false==0 and 0=="0" then false=="0" because equivalence is
transitive. So if false is empty, then "0" is empty because false=="0".

If you want to check that a string's length is non-zero you can use
strlen().

------------------------------------------------------------------------

[2010-01-20 20:15:02] seanr at webolutionary dot com

Description:
------------
If the value is a string of "0", than it's not a true zero right?  The

behavior of empty() in this case is utterly absurd.  If you can't fix 
empty, there needs to be a new function to provide a better way to 
test on this than writing our own special functions to work around a 
PHP bug.

$a = 0;
$b = '';
$b = '0'

empty($a) returns true (correctly, but not helpfully)
empty($b) returns true (correctly)
empty($a) returns true (incorrectly, since it actually does have a 
value)

Of course, isset() returns true for all three (correctly, but not 
helpfully).  This means there's no way to find out that $a and $c have

values I can use and $b doesn't without writing my own special 
function or if statement.  EXTREMELY frustrating.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50809&edit=1

Reply via email to