Bug #76186 [NEW]: ArrayIterator is always Json encoded as an Object

From: Date: Thu, 05 Apr 2018 14:01:54 +0000
Subject: Bug #76186 [NEW]: ArrayIterator is always Json encoded as an Object
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214618@lists.php.net to get a copy of this message
From: lionel at lionelmartin dot eu Operating system: Linux PHP version: 5.6.35 Package: SPL related Bug Type: Bug Bug description:ArrayIterator is always Json encoded as an Object Description: ------------ When using json_encode on an ArrayIterator (or ArrayObject), the result is always an object contrary to its json_encoded array representation. Test script: --------------- $array = ['my', 'test', 'array']; $arrayObject = new \ArrayObject($array); $arrayIterator = $arrayObject->getIterator(); echo json_encode($array); echo json_encode($arrayObject); echo json_encode($arrayIterator); Expected result: ---------------- ["my","test","array"] ["my","test","array"] ["my","test","array"] Actual result: -------------- ["my","test","array"] {"0":"my","1":"test","2":"array"} {"0":"my","1":"test","2":"array"} -- Edit bug report at https://bugs.php.net/bug.php?id=76186&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76186&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76186&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76186&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76186&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76186&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76186&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76186&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76186&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76186&r=support Expected behavior: https://bugs.php.net/fix.php?id=76186&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76186&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76186&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76186&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76186&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76186&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76186&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76186&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76186&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76186&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76186&r=mysqlcfg

« previous php.bugs (#214618) next »