Bug #75717 [Fbk->Csd]: RecursiveArrayIterator does not traverse arrays by reference
| From: | nikic@php.net | Date: | Fri, 22 Dec 2017 17:02:13 +0000 |
| Subject: | Bug #75717 [Fbk->Csd]: RecursiveArrayIterator does not traverse arrays by reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-213245@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75717&edit=1
ID: 75717
Updated by: nikic@php.net
Reported by: greg at girty dot net
Summary: RecursiveArrayIterator does not traverse arrays by
reference
-Status: Feedback
+Status: Closed
Type: Bug
Package: SPL related
Operating System: OSX, Debian Linux
PHP Version: 7.1.12
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ccb113c3e5964ef2d2e5b4ae3e67d61702db9bfc
Log: Fixed bug #75717
Previous Comments:
------------------------------------------------------------------------
[2017-12-21 17:33:11] greg at girty dot net
I created https://bugs.php.net/bug.php?id=75716
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-21 16:22:13] peehaa@php.net
Isn't this a dupe of https://bugs.php.net/bug.php?id=75716 ?
------------------------------------------------------------------------
[2017-12-21 16:17:27] 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.
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
some nested items
Actual result:
--------------
some nested items
Notice: Array to string conversion ... on line 8
Array nested items
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75717&edit=1