From:
Operating system: RedHat
PHP version: 5.3.10
Package: Arrays related
Bug Type: Bug
Bug description:Unable to access key in array cast from object
Description:
------------
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;
var_dump($array)
Expected result:
----------------
Hello 1
array(1) {
["804496778"]=>
string(5) "Hello"
}
Actual result:
--------------
PHP Notice: Undefined index: 804496778 in /home/icewolf/bug.php on line 6
0
array(1) {
["804496778"]=>
string(5) "Hello"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=61655&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=61655&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=61655&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=61655&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=61655&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=61655&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=61655&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=61655&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=61655&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=61655&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=61655&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=61655&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=61655&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=61655&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=61655&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=61655&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=61655&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=61655&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=61655&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=61655&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=61655&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=61655&r=mysqlcfg