From f14b6f49209b360018224aec38e8ea94fcf3dbf4 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 22 Dec 2017 18:11:38 +0100 Subject: [PATCH] Fixed bug #73209 --- NEWS | 2 ++ ext/spl/spl_array.c | 9 +++++++++ ext/spl/tests/bug73209.phpt | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 ext/spl/tests/bug73209.phpt diff --git a/NEWS b/NEWS index d474e9fd08..478d889325 100644 --- 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 diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 105fb269d6..907e77888c 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -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 index 0000000000..7383940936 --- /dev/null +++ b/ext/spl/tests/bug73209.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #73209: RecursiveArrayIterator does not iterate object properties +--FILE-- +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 -- 2.40.0