|  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: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
32 + 25 = ?
Subscribe to this entry?

 [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-2022 The PHP Group
All rights reserved.
Last updated: Sun Aug 14 10:05:44 2022 UTC