Bug #68682 [Opn]: RecursiveIteratorIterator does not recurse

From: Date: Mon, 29 Dec 2014 10:35:41 +0000
Subject: Bug #68682 [Opn]: RecursiveIteratorIterator does not recurse
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189306@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68682&edit=1 ID: 68682 User updated by: spinkus at epicmorsel dot com Reported by: spinkus at epicmorsel dot com Summary: RecursiveIteratorIterator does not recurse Status: Open Type: Bug Package: SPL related Operating System: Linux PHP Version: 5.4.35 Block user comment: N Private report: N New Comment: Confirmed. In example data [1, 2, new X(), 5], the getIterator() method of the X instance is never called. Previous Comments: ------------------------------------------------------------------------ [2014-12-29 10:31:12] spinkus at epicmorsel dot com Hmm, just realised it's probably more likely RecursiveIteratorIterator is treating the object in the array [1,2, new X(), 5] as an object and iterating its public fields. Investigating. ------------------------------------------------------------------------ [2014-12-29 10:08:26] spinkus at epicmorsel dot com Description: ------------ RecursiveIteratorIterator fails to Recurse into class implementing iteratorAggregate and returning RecursiveArrayIterator on private data. See test script. Test script: --------------- class X implements IteratorAggregate { private $data = ['X', 'X', 'X']; # public $data = ['X', 'X', 'X']; public function __construct($data = null) { $this->data = isset($data) ? $data : $this->data; } public function getIterator() { return new RecursiveArrayIterator($this->data); } } $x = new X([1, 2, new X(), 5]); $it = new RecursiveIteratorIterator($x); foreach($it as $v) { var_dump($v); } Expected result: ---------------- Expecting no difference between public and private data. RecursiveArrayIterator should make a copy of the private data on construction. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68682&edit=1

« previous php.bugs (#189306) next »