|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27677 isset() gives false positives for array subkeys
Submitted: 2004-03-24 13:39 UTC Modified: 2004-03-26 11:04 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rattray at purdue dot edu Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 4.3.4 OS: windows and unix
Private report: No CVE-ID: None
 [2004-03-24 13:39 UTC] rattray at purdue dot edu
using isset() to detect the existence of array subkeys give a false positive.  Also, trying to print the content of said non-existing keys gives the first character of the parent key!

Reproduce code:
$aArray = array();
$aArray["key"] = "value";
print("<PRE>".print_r($aArray, true)."</PRE>");
if (isset($aArray))
	print("Array exists<BR>");
else print("Array does not exist.<BR>");
if (isset($aArray["key"]))
	print("Array[key] exists, value = '".$aArray["key"]."'<BR>");
else print("Array[key] does not exist.<BR>");
if (isset($aArray["key"]["subkey"]))
	print("Array[key][subkey] exists, value = '".$aArray["key"]["subkey"]."'<BR>");
else print("Array[key][subkey] does not exist.<BR>");

Expected result:
    [key] => value

Array exists
Array[key] exists, value = 'value'
Array[key][subkey] does not exist

Actual result:
    [key] => value

Array exists
Array[key] exists, value = 'value'
Array[key][subkey] exists, value = 'v'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-25 15:50 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The string key when accessing a portion of another string 
is converted to an integer. Because it is a string it gets 
converted to 0, so you end up accessing the 1st letter of 
the 1st word. 
 [2004-03-26 08:29 UTC] rattray at purdue dot edu
If this is not a bug, then why does the code work as I expected it to in PHP 5.0.0RC1?
 [2004-03-26 11:04 UTC]
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 06:01:29 2024 UTC