Skip to content

Commit

Permalink
Fixed bug #73209
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Dec 22, 2017
1 parent ec142f2 commit f14b6f4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions ext/spl/tests/bug73209.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f14b6f4

Please sign in to comment.