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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 23:01:27 2025 UTC