|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61655 Unable to access key in array cast from object
Submitted: 2012-04-06 23:49 UTC Modified: 2016-11-14 18:30 UTC
From: phpbugs at deep-freeze dot ca Assigned: ajf (profile)
Status: Closed Package: Arrays related
PHP Version: 5.3.10 OS: RedHat
Private report: No CVE-ID: None
 [2012-04-06 23:49 UTC] phpbugs at deep-freeze dot ca
Casting from an object to an array with numeric key leaves the element inaccessible.

Given a object with a field whose name is numeric, after a cast to array, there is no means to access the element.

That is  $array['804496778'] yields an undefined error
array_key_exists(804496778, $array); yields false
array_key_exists('804496778', $array); fields false
yet a var_dump($array); shows this element;
and a array_keys($array); returns array(1) { [0] string(9) "804496778" }

Test script:
$object = new stdClass();
$key = '804496778';
$object->{$key} = "Hello;
$array = (array)$object;
echo $array[$key], ' ', (int)array_key_exists($key, $array), PHP_EOL;

Expected result:
Hello 1
array(1) {
  string(5) "Hello"

Actual result:
PHP Notice:  Undefined index: 804496778 in /home/icewolf/bug.php on line 6
array(1) {
  string(5) "Hello"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-09 02:52 UTC] reeze dot xia at gmail dot com
   in a object property lookup by name always in string, but in array numeric 
string(like "22200" ) key will transform to numeric but not a string anymore.
    when conversion internal HashTable did't changed so after conversion, key 
lookup will fail.
as you posted:
array(1) {
  string(5) "Hello"
the key is string but not number.
if you do like this:

$array["1000"] = "value"

array(1) {
  string(5) "value"

see ? "1000" changed to 1000.

I've post a discussion about this in internal list.
 [2012-04-09 03:22 UTC]
-Status: Open +Status: Not a bug
 [2012-04-09 03:22 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

This is a documented behavior, plz lok at: 

Fixing that implies a perfomance decrease.
 [2016-11-14 18:30 UTC]
-Status: Not a bug +Status: Closed -Assigned To: +Assigned To: ajf
 [2016-11-14 18:30 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

Fixed by:
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC