xref: /PHP-7.1/ext/spl/tests/bug75717.phpt (revision ccb113c3)
1--TEST--
2Bug #75717: RecursiveArrayIterator does not traverse arrays by reference
3--FILE--
4<?php
5
6function flatten(array $nestedArraysAndStrings){
7    $flat=[];
8    $iter = new RecursiveIteratorIterator(
9        new RecursiveArrayIterator($nestedArraysAndStrings));
10    foreach($iter as $leaf){ $flat[] = $leaf; }
11    return join(NULL, $flat);
12}
13
14$noRefs = [[[['some']]],[' nested '],"items"];
15
16$withRefs = []+$noRefs;
17$wat = $noRefs[0];
18$withRefs[0] = &$wat;
19
20echo flatten($noRefs), "\n";
21echo flatten($withRefs), "\n";
22
23?>
24--EXPECT--
25some nested items
26some nested items
27