From: Marcus Boerger <helly@php.net>
Date: Mon, 3 Oct 2005 09:12:39 +0000 (+0000)
Subject: - Fix issue with RecursiveArrayIterator::getChildren()
X-Git-Tag: RELEASE_0_9_0~44
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1fc84f584bfcf8b541eb03a98e651c347351b97;p=php

- Fix issue with RecursiveArrayIterator::getChildren()
---

diff --git a/ext/spl/examples/class_tree.php b/ext/spl/examples/class_tree.php
index 128eebec58..07741a7dd8 100755
--- a/ext/spl/examples/class_tree.php
+++ b/ext/spl/examples/class_tree.php
@@ -62,11 +62,6 @@ class SubClasses extends RecursiveArrayIterator
 		}
 	}
 	
-	function getChildren()
-	{
-		return parent::current();
-	}
-	
 	function current()
 	{
 		return parent::key();
diff --git a/ext/spl/internal/recursivearrayiterator.inc b/ext/spl/internal/recursivearrayiterator.inc
index 1b4497afd8..e583c734b4 100755
--- a/ext/spl/internal/recursivearrayiterator.inc
+++ b/ext/spl/internal/recursivearrayiterator.inc
@@ -13,7 +13,7 @@
  * @brief   A recursive array iterator
  * @author  Marcus Boerger
  * @version 1.0
- * @since PHP 6.0
+ * @since PHP 5.1
  *
  * Passes the RecursiveIterator interface to the inner Iterator and provides
  * the same functionality as FilterIterator. This allows you to skip parents
@@ -42,6 +42,10 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
 	 */
 	function getChildren()
 	{
+		if ($this->current() instanceof self)
+		{
+			return $this->current();
+		}
 		if (empty($this->ref))
 		{
 			$this->ref = new ReflectionClass($this);
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index b954b22569..cd75a161d2 100755
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -1204,6 +1204,10 @@ SPL_METHOD(Array, getChildren)
 		return;
 	}
 
+	if (Z_TYPE_PP(entry) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(entry), Z_OBJCE_P(getThis()) TSRMLS_CC)) {
+		RETURN_ZVAL(*entry, 0, 0);
+	}
+
 	spl_instantiate_arg_ex1(Z_OBJCE_P(getThis()), &return_value, 0, *entry TSRMLS_CC);
 }
 /* }}} */