#44063 [Opn->Bgs]: RecursiveIteratorIterator needs rewind right after creation
| From: | helly@php.net | Date: | Thu, 07 Feb 2008 09:32:04 +0000 |
| Subject: | #44063 [Opn->Bgs]: RecursiveIteratorIterator needs rewind right after creation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122064@lists.php.net to get a copy of this message | ||
ID: 44063
Updated by: helly@php.net
Reported By: smirnov at h-type dot com
-Status: Open
+Status: Bogus
Bug Type: SPL related
-Operating System: Windows
+Operating System: *
PHP Version: 5.2.5
-Assigned To:
+Assigned To: helly
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Flipe, your assumption is wrong. Adding rewind to the constructor would
result in a doubled call to rewind on the ArrayIterator.
Now the whole Iterator collection is designed to not duplicate any
calls and to be used by foreach. So you are basically missing the rewind
call, which by the way all examples with while have (at least my own
ones).
I might however look into this again and check whether I can do
something about the starting value in case of the missing rewind call on
the ArrayIterator.
Previous Comments:
------------------------------------------------------------------------
[2008-02-07 01:07:59] felipe@php.net
Marcus, is my impression or is missing a rewind in this constructor?
http://felipe.ath.cx/diff/bug44063.diff
------------------------------------------------------------------------
[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