Skip to content

Commit 184309c

Browse files
committed
- MFH Fix issue with RecursiveArrayIterator::getChildren()
1 parent 594fd87 commit 184309c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

ext/spl/examples/class_tree.php

-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ function __construct($base, $check_interfaces = false)
6262
}
6363
}
6464

65-
function getChildren()
66-
{
67-
return parent::current();
68-
}
69-
7065
function current()
7166
{
7267
return parent::key();

ext/spl/internal/recursivearrayiterator.inc

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @brief A recursive array iterator
1414
* @author Marcus Boerger
1515
* @version 1.0
16-
* @since PHP 6.0
16+
* @since PHP 5.1
1717
*
1818
* Passes the RecursiveIterator interface to the inner Iterator and provides
1919
* the same functionality as FilterIterator. This allows you to skip parents
@@ -42,6 +42,10 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
4242
*/
4343
function getChildren()
4444
{
45+
if ($this->current() instanceof self)
46+
{
47+
return $this->current();
48+
}
4549
if (empty($this->ref))
4650
{
4751
$this->ref = new ReflectionClass($this);

ext/spl/spl_array.c

+4
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,10 @@ SPL_METHOD(Array, getChildren)
11861186
if (zend_hash_get_current_data_ex(aht, (void **) &entry, &intern->pos) == FAILURE) {
11871187
return;
11881188
}
1189+
1190+
if (Z_TYPE_PP(entry) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(entry), Z_OBJCE_P(getThis()) TSRMLS_CC)) {
1191+
RETURN_ZVAL(*entry, 0, 0);
1192+
}
11891193

11901194
spl_instantiate_arg_ex1(Z_OBJCE_P(getThis()), &return_value, 0, *entry TSRMLS_CC);
11911195
}

0 commit comments

Comments
 (0)