php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11254 isset() and empty() doesn't work with hash arrays
Submitted: 2001-06-02 22:23 UTC Modified: 2001-06-13 18:01 UTC
From: gabriel dot barros at folha dot com dot br Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: rh 7.1
Private report: No CVE-ID: None
 [2001-06-02 22:23 UTC] gabriel dot barros at folha dot com dot br
$t1 = array("nome"=>"gabriel", "idade"=>"19");
$t2 = "asd";
$t3 = NULL ;

echo "<br><br>\n\n1: " . isset($t1{"nome"});
echo "<br><br>\n\n2: " . isset($t2{"nome"}); # there's NO "nome" defined! shouldn't it return FALSE? why does it retur TRUE ???
echo "<br><br>\n\n3: " . isset($t3{"nome"});
echo "<br><br>\n\n4: " . isset($t4{"nome"});
echo "<br><br>";
echo "<br><br>\n\n1: " . empty($t1{"nome"});
echo "<br><br>\n\n2: " . empty($t2{"nome"}); # It doesn't even exist! how can it be not even empty ???
echo "<br><br>\n\n3: " . empty($t3{"nome"});
echo "<br><br>\n\n4: " . empty($t4{"nome"});

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-13 18:01 UTC] cardinal@php.net
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'}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 22:01:33 2024 UTC