|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60552 Nonexistent array element is assigned a value
Submitted: 2011-12-17 22:41 UTC Modified: 2011-12-18 03:34 UTC
From: gmtfn at yahoo dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.8 OS:
Private report: No CVE-ID:
 [2011-12-17 22:41 UTC] gmtfn at yahoo dot com
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'];


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-18 03:30 UTC] 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:
 [2011-12-18 03:34 UTC]
-Status: Open +Status: Bogus
 [2011-12-18 03:34 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

pseudo code:
 => 'search'["fileter"]
   => 'search'[0]
    => 's'
 [2011-12-19 02:33 UTC] gmtfn at yahoo dot com
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:

 => '5'["filter"]
   => '5'[0]
    => '5'
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 22:01:33 2015 UTC