#50809 [Opn]: empty(), isset() not helpful - need better alternative

From: Date: Thu, 21 Jan 2010 12:28:32 +0000
Subject: #50809 [Opn]: empty(), isset() not helpful - need better alternative
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146847@lists.php.net to get a copy of this message
 ID:               50809
 Updated by:       colder@php.net
 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] degeberg@php.net

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



Thread (4 messages)

« previous php.bugs (#146847) next »