Bug #60552 [Com]: Nonexistent array element is assigned a value
| From: | anon at anon dot anon | Date: | Sun, 18 Dec 2011 03:30:09 +0000 |
| Subject: | Bug #60552 [Com]: Nonexistent array element is assigned a value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-165944@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60552&edit=1
ID: 60552
Comment by: anon at anon dot anon
Reported by: gmtfn at yahoo dot com
Summary: Nonexistent array element is assigned a value
Status: Open
Type: Bug
Package: Arrays related
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
It's an unfortunate quirk but it's not a bug. You're doing string access by character
index. The string 'filter' gets parsed as an integer, which yields 0 since it's an
invalid number, and the character at index 0 in the string '5' is '5'. See the
warning here:
http://www.php.net/manual/en/language.types.string.php#language.types.string.substr
Previous Comments:
------------------------------------------------------------------------
[2011-12-17 22:41:34] gmtfn at yahoo dot com
Description:
------------
In the code sample provided, for some reason, $nonexistentElement gets assigned a value of 5.
I'd expect this to trigger an error.
Test script:
---------------
$params = array('search'=>'5');
$nonexistentElement = $params['search']['filter'];
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60552&edit=1