Doc->Bug #75716 [Csd->Dup]: RecursiveArrayIterator does not traverse vars by reference
| From: | requinix@php.net | Date: | Thu, 21 Dec 2017 16:18:29 +0000 |
| Subject: | Doc->Bug #75716 [Csd->Dup]: RecursiveArrayIterator does not traverse vars by reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213218@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75716&edit=1
ID: 75716
Updated by: requinix@php.net
Reported by: greg at girty dot net
Summary: RecursiveArrayIterator does not traverse vars by
reference
-Status: Closed
+Status: Duplicate
-Type: Documentation Problem
+Type: Bug
Package: SPL related
Operating System: OSX, linux
PHP Version: 7.1.12
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2017-12-21 16:12:20] greg at girty dot net
mixed expected and actual results, closing and resubmitting a corrected version
------------------------------------------------------------------------
[2017-12-21 16:08:49] greg at girty dot net
Description:
------------
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.
Submitter has tested this in OSX and Debian Linux, others likely affected.
HHVM gives the expected result, see https://3v4l.org/up3me
Test script:
---------------
function flatten(array $nestedArraysAndStrings){
$flat=[];
$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 n
Notice: Array to string conversion in /in/up3me on line 8
Array nested items n
Actual result:
--------------
some nested items
some nested items
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75716&edit=1