#44063 [Opn]: RecursiveIteratorIterator needs rewind right after creation

From: Date: Thu, 07 Feb 2008 01:08:02 +0000
Subject: #44063 [Opn]: RecursiveIteratorIterator needs rewind right after creation
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122058@lists.php.net to get a copy of this message
ID: 44063 Updated by: felipe@php.net Reported By: smirnov at h-type dot com Status: Open Bug Type: SPL related Operating System: Windows PHP Version: 5.2.5 New Comment: Marcus, is my impression or is missing a rewind in this constructor? http://felipe.ath.cx/diff/bug44063.diff Previous Comments: ------------------------------------------------------------------------ [2008-02-06 14:28:08] smirnov at h-type dot com Description: ------------ RecursiveIteratorIterator returns one extra result if we don't provide rewind() before while. Reproduce code: --------------- $array = array( array('name'=>'butch', 'sex'=>'male'), array('name'=>'fido', 'sex'=>'male'), array('name'=>'girly','sex'=>'female') ); $it=new RecursiveIteratorIterator(new RecursiveArrayIterator($array)); //$it->rewind(); //The result will be as expected if uncomment this while($it->valid()){ echo $it->key().' -- '.$it->current()."\n"; $it->next(); } Expected result: ---------------- name -- butch sex -- male name -- fido sex -- male name -- girly sex -- female Actual result: -------------- 0 -- Array name -- butch sex -- male name -- fido sex -- male name -- girly sex -- female ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44063&edit=1

« previous php.bugs (#122058) next »