php.net |  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
Votes:1
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
Description:
------------
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:
----------------
Array
(
    [key] => value
)

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

Actual result:
--------------
Array
(
    [key] => value
)

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

Patches

Pull Requests

History

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

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] derick@php.net
.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC