diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2017-12-22 18:11:38 +0100 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2017-12-22 18:22:00 +0100 |
| commit | f14b6f49209b360018224aec38e8ea94fcf3dbf4 (patch) | |
| tree | 83d9b59a1b56aa89f71511cdead145142f0c35ad | |
| parent | ec142f2c86c28b970aef631a5750f6a02b954089 (diff) | |
| download | php-git-f14b6f49209b360018224aec38e8ea94fcf3dbf4.tar.gz | |
Fixed bug #73209
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | ext/spl/spl_array.c | 9 | ||||
| -rw-r--r-- | ext/spl/tests/bug73209.phpt | 28 |
3 files changed, 39 insertions, 0 deletions
@@ -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-- +<?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 |
