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

diff --git a/NEWS b/NEWS
index d474e9fd0866c13ebfac92b307dbdf48cf5e2ccc..478d8893252acab27fabd95527a81cc6af3e6fcf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,8 @@ PHP                                                                        NEWS
     reference). (Nikita)
   . Fixed bug #75242 (RecursiveArrayIterator doesn't have constants from parent
     class). (Nikita)
+  . Fixed bug #73209 (RecursiveArrayIterator does not iterate object
+    properties). (Nikita)
 
 04 Jan 2018, PHP 7.1.13
 
index 105fb269d6e81e86491518651d51f2a294040785..907e77888ccd53a9d7ae08faf334d5ae072f7a5b 100644 (file)
@@ -1642,6 +1642,10 @@ SPL_METHOD(Array, hasChildren)
                RETURN_FALSE;
        }
 
+       if (Z_TYPE_P(entry) == IS_INDIRECT) {
+               entry = Z_INDIRECT_P(entry);
+       }
+
        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));
 }
@@ -1667,6 +1671,11 @@ SPL_METHOD(Array, getChildren)
                return;
        }
 
+       if (Z_TYPE_P(entry) == IS_INDIRECT) {
+               entry = Z_INDIRECT_P(entry);
+       }
+
+       ZVAL_DEREF(entry);
        if (Z_TYPE_P(entry) == IS_OBJECT) {
                if ((intern->ar_flags & SPL_ARRAY_CHILD_ARRAYS_ONLY) != 0) {
                        return;
diff --git a/ext/spl/tests/bug73209.phpt b/ext/spl/tests/bug73209.phpt
new file mode 100644 (file)
index 0000000..7383940
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Bug #73209: RecursiveArrayIterator does not iterate object properties
+--FILE--
+<?php
+
+class hello {
+  public $props = array();
+  function __construct() {
+    $this->props = ['hello' => 5, 'props' => ['keyme' => ['test' => 5]]];
+  }
+}
+$data = new hello();
+
+$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data), RecursiveIteratorIterator::SELF_FIRST);
+echo "Expect to see all keys in ->props here: \n";
+
+foreach($iterator as $k=>$v) {
+    echo $k . "\n";
+}
+
+?>
+--EXPECT--
+Expect to see all keys in ->props here: 
+props
+hello
+props
+keyme
+test