]> granicus.if.org Git - php/commitdiff
Fixed bug #75717
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Dec 2017 17:00:17 +0000 (18:00 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 22 Dec 2017 17:01:03 +0000 (18:01 +0100)
NEWS
ext/spl/spl_array.c
ext/spl/tests/bug75717.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 2483bd6bc801f3ff4774a23d1ec7181db34e3d7b..c7d75f15037e4e08169ae5aa8bb59870513d5567 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
 
index 81bbe48bd47a919504a1fd1d9091f7339c6564a0..1be55d785b79e9ef60a813d6e974c069d2540b15 100644 (file)
@@ -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));
 }
 /* }}} */
diff --git a/ext/spl/tests/bug75717.phpt b/ext/spl/tests/bug75717.phpt
new file mode 100644 (file)
index 0000000..485b9d8
--- /dev/null
@@ -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