From: smirnov at h-type dot com
Operating system: Windows
PHP version: 5.2.5
PHP Bug Type: SPL related
Bug description: RecursiveIteratorIterator needs rewind right after creation
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 bug report at http://bugs.php.net/?id=44063&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=44063&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44063&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44063&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44063&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44063&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44063&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44063&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44063&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44063&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44063&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44063&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44063&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44063&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44063&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=44063&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=44063&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44063&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44063&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44063&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44063&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44063&r=mysqlcfg