#46818 [Bgs]: ParentIterator Initializing

From: Date: Wed, 10 Dec 2008 23:08:28 +0000
Subject: #46818 [Bgs]: ParentIterator Initializing
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-131883@lists.php.net to get a copy of this message
ID: 46818 User updated by: kosugi at kips dot gr dot jp Reported By: kosugi at kips dot gr dot jp Status: Bogus Bug Type: SPL related Operating System: Linux 2.6.18 PHP Version: 5.2.8 New Comment: I got expected result with "this->rewind()" in constructor. class pi extends ParentIterator { public function __construct($iterator) { parent::__construct($iterator); $this->rewind(); } } Previous Comments: ------------------------------------------------------------------------ [2008-12-10 05:36:38] kosugi at kips dot gr dot jp It is a gross misunderstanding. ------------------------------------------------------------------------ [2008-12-10 05:22:53] kosugi at kips dot gr dot jp Description: ------------ ParentIterator that only shows those elements which have children. But I can't get the expected result without rewind() in starting an iteration. Reproduce code: --------------- $target = array( 'foo' => array(1,2,3), 'bar' => array(11,12,13), 'baz' ); $rai = new RecursiveArrayIterator($target); $pi = new ParentIterator($rai); //$pi->rewind(); while ($pi->valid()) { var_dump($pi->current()); $pi->next(); } Expected result: ---------------- array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(5) { [0]=> int(11) [1]=> int(12) [2]=> int(13) } Actual result: -------------- // no output ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46818&edit=1

« previous php.bugs (#131883) next »