Bug #72254 [NEW]: get_object_vars() returns unusable result when keys are numeric

From: Date: Mon, 23 May 2016 00:47:12 +0000
Subject: Bug #72254 [NEW]: get_object_vars() returns unusable result when keys are numeric
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201227@lists.php.net to get a copy of this message
From: unirgy at gmail dot com Operating system: Any PHP version: 7.0.6 Package: Unknown/Other Function Bug Type: Bug Bug description:get_object_vars() returns unusable result when keys are numeric Description: ------------ If argument in get_object_vars() has numeric keys, the resulting array is built using numeric string keys, which apparently can't be referenced. Test script: --------------- $json = '{"1":"A"}'; $arrWorks = json_decode($json, true); var_dump($arrWorks); var_dump($arrWorks[1], $arrWorks['1']); echo "\n=================\n"; $arrDoesntWork = get_object_vars(json_decode($json)); var_dump($arrDoesntWork); var_dump($arrDoesntWork[1], $arrDoesntWork['1']); Expected result: ---------------- array(1) { [1]=> string(1) "A" } string(1) "A" string(1) "A" ================= array(1) { [1]=> string(1) "A" } string(1) "A" string(1) "A" Actual result: -------------- array(1) { [1]=> string(1) "A" } string(1) "A" string(1) "A" ================= array(1) { ["1"]=> string(1) "A" } Notice: Undefined offset: 1 in /in/bbleq on line 12 Notice: Undefined offset: 1 in /in/bbleq on line 12 NULL NULL -- Edit bug report at https://bugs.php.net/bug.php?id=72254&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72254&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72254&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72254&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72254&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72254&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72254&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72254&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72254&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72254&r=support Expected behavior: https://bugs.php.net/fix.php?id=72254&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72254&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72254&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72254&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72254&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72254&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72254&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72254&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72254&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72254&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72254&r=mysqlcfg

« previous php.bugs (#201227) next »