| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 Patchesmfa (last revision 2024-07-02 11:26 UTC by admin at mfa dot akd dot ac dot id)Pull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2018-04-05 14:14 UTC] fractalesque at gmail dot com
  [2018-04-05 14:39 UTC] requinix@php.net
 
-Summary:     ArrayIterator is always Json encoded as an
              Object
+Summary:     ArrayObject should be able to be Json encoded
              as an Array
-Type:        Bug
+Type:        Feature/Change Request
-PHP Version: 5.6.35
+PHP Version: 7.1
  [2018-04-05 14:39 UTC] requinix@php.net
  [2024-07-02 11:26 UTC] admin at mfa dot akd dot ac dot id
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Mon Nov 03 03:00:01 2025 UTC | 
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"}