|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75717 RecursiveArrayIterator does not traverse arrays by reference
Submitted: 2017-12-21 16:17 UTC Modified: 2017-12-21 16:30 UTC
From: greg at girty dot net Assigned:
Status: Closed Package: SPL related
PHP Version: 7.1.12 OS: OSX, Debian Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: greg at girty dot net
New email:
PHP Version: OS:


 [2017-12-21 16:17 UTC] greg at girty dot net
The expected behaviour of RecursiveArrayIterator is that only leaf nodes will be iterated, but if an array is contained by reference, it is not traversed, instead it is returned by next().

Explicit use of RecursiveIteratorIterator::LEAVES_ONLY has no affect.

HHVM gives the expected result, see 

Test script:
function flatten(array $nestedArraysAndStrings){
    $iter = new RecursiveIteratorIterator(
        new RecursiveArrayIterator($nestedArraysAndStrings));
    foreach($iter as $leaf){ $flat[] = $leaf; }
    return join(NULL, $flat);

$noRefs = [[[['some']]],[' nested ']," items \n"];

$withRefs = []+$noRefs;
$wat = $noRefs[0];
$withRefs[0] = &$wat;

echo flatten($noRefs);
echo flatten($withRefs);

Expected result:
some nested  items 
some nested  items 

Actual result:
some nested  items 
Notice: Array to string conversion ... on line 8
Array nested  items 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-21 16:22 UTC]
Isn't this a dupe of ?
 [2017-12-21 16:30 UTC]
-Status: Open +Status: Feedback
 [2017-12-21 17:33 UTC] greg at girty dot net
I created with errors, and closed it when I realized the mistake. (My first bug submission, forgive me I didn't know how to correct 75716, revoke it, or mark it as erroneous.)

This is the correct version.
 [2017-12-22 17:02 UTC]
Automatic comment on behalf of
Log: Fixed bug #75717
 [2017-12-22 17:02 UTC]
-Status: Feedback +Status: Closed
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jan 26 09:03:33 2022 UTC