Skip to content

Commit

Permalink
Fixed bug #75717
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Dec 22, 2017
1 parent 0246373 commit ccb113c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ PHP NEWS

- SOAP:
. Fixed bug #70469 (SoapClient generates E_ERROR even if exceptions=1 is
used). (Anton Artamonov)
used). (Anton Artamonov)

- SPL:
. Fixed bug #75717 (RecursiveArrayIterator does not traverse arrays by
reference). (Nikita)

04 Jan 2018, PHP 7.1.13

Expand Down
1 change: 1 addition & 0 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,7 @@ SPL_METHOD(Array, hasChildren)
RETURN_FALSE;
}

ZVAL_DEREF(entry);
RETURN_BOOL(Z_TYPE_P(entry) == IS_ARRAY || (Z_TYPE_P(entry) == IS_OBJECT && (intern->ar_flags & SPL_ARRAY_CHILD_ARRAYS_ONLY) == 0));
}
/* }}} */
Expand Down
26 changes: 26 additions & 0 deletions ext/spl/tests/bug75717.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Bug #75717: RecursiveArrayIterator does not traverse arrays by reference
--FILE--
<?php

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"];

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

echo flatten($noRefs), "\n";
echo flatten($withRefs), "\n";

?>
--EXPECT--
some nested items
some nested items

0 comments on commit ccb113c

Please sign in to comment.