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