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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gabriel dot barros at folha dot com dot br
New email:
PHP Version: OS:

 

 [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: Tue Apr 23 08:01:30 2024 UTC