From:
Operating system: *
PHP version: 5.3.5
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Inconsistent array index behaviour
Description:
------------
It is well known that PHP casts numeric string indexes to integers, and it
is normally impossible to force such indexes to remain strings. For
example, the script below will output "integer":
$test = array("123" => 1);
echo gettype(key($test)); // integer
However, it is possible to achieve this if we assign numeric string
property to an object (by using the ->{} syntax), and then cast it to
array. Not only will the index retain it's string type, but it will also be
impossible to access that index with [], which can't be correct behaviour.
See attached example.
Test script:
---------------
<?php
$test = new stdClass();
$test->{"123"} = 1;
$test = (array)$test;
$key = key($test);
echo gettype($key);
echo "\n";
echo $test[$key];
?>
Expected result:
----------------
integer
1
Actual result:
--------------
string
PHP Notice: Undefined index: 123 in test.php on line 9
--
Edit bug report at http://bugs.php.net/bug.php?id=54209&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54209&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54209&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54209&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54209&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54209&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54209&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54209&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54209&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54209&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54209&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54209&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54209&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54209&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54209&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54209&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54209&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54209&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54209&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54209&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54209&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54209&r=mysqlcfg