Bug #60552 [Com]: Nonexistent array element is assigned a value
| From: | gmtfn at yahoo dot com | Date: | Mon, 19 Dec 2011 02:33:35 +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-165955@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: gmtfn at yahoo dot com
Reported by: gmtfn at yahoo dot com
Summary: Nonexistent array element is assigned a value
Status: Bogus
Type: Bug
Package: Arrays related
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
Thank you both. Because of this, I've switched to using an object in place of an array where I
noticed this behavior.
By the way,
The correct pseudo code is:
$params['search']['filter']
=> '5'["filter"]
=> '5'[0]
=> '5'
Previous Comments:
------------------------------------------------------------------------
[2011-12-18 03:34:04] laruence@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
pseudo code:
$params['search']['filter']
=> 'search'["fileter"]
=> 'search'[0]
=> 's'
------------------------------------------------------------------------
[2011-12-18 03:30:09] anon at anon dot anon
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
------------------------------------------------------------------------
[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