Bug #11254 Updated: isset() and empty() doesn't work with hash arrays
| From: | cardinal@php.net | Date: | Wed, 13 Jun 2001 22:01:06 +0000 |
| Subject: | Bug #11254 Updated: isset() and empty() doesn't work with hash arrays | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-56724@lists.php.net to get a copy of this message | ||
ID: 11254
Updated by: cardinal
Reported By: gabriel.barros@folha.com.br
Old-Status: Open
Status: Bogus
Bug Type: Scripting Engine problem
Operating system:
PHP Version: 4.0.4pl1
Assigned To:
Comments:
isset($t2{"nome"}) is evaluating to true because you're
using a string as an array, which is a perfectly legal
thing to do. In this case, "nome" is being evaluated to
zero (As all strings evaluate to) and the isset is seeing
that $t2{0} exists, it's 'a' in the string 'asd'.
Side note, it's not recommended to use curly braces when
accessing array elements. Use square brackets instead,
$array['key'] instead of $array{'key'}
Previous Comments:
---------------------------------------------------------------------------
[2001-06-02 22:23:01] gabriel.barros@folha.com.br
$t1 = array("nome"=>"gabriel", "idade"=>"19");
$t2 = "asd";
$t3 = NULL ;
echo "<br><br>nn1: " . isset($t1{"nome"});
echo "<br><br>nn2: " . isset($t2{"nome"}); # there's NO
"nome" defined! shouldn't it return FALSE? why does it retur TRUE ???
echo "<br><br>nn3: " . isset($t3{"nome"});
echo "<br><br>nn4: " . isset($t4{"nome"});
echo "<br><br>";
echo "<br><br>nn1: " . empty($t1{"nome"});
echo "<br><br>nn2: " . empty($t2{"nome"}); # It doesn't even
exist! how can it be not even empty ???
echo "<br><br>nn3: " . empty($t3{"nome"});
echo "<br><br>nn4: " . empty($t4{"nome"});
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=11254&edit=2