#49104 [Opn->Asn]: AppendIterator::append($iterator) calls $iterator->rewind() with no reason

From: Date: Sun, 02 Aug 2009 16:07:20 +0000
Subject: #49104 [Opn->Asn]: AppendIterator::append($iterator) calls $iterator->rewind() with no reason
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-140580@lists.php.net to get a copy of this message
 ID:               49104
 Updated by:       felipe@php.net
 Reported By:      seva dot lapsha at gmail dot com
-Status:           Open
+Status:           Assigned
 Bug Type:         SPL related
 Operating System: *
 PHP Version:      5.3.0
-Assigned To:      
+Assigned To:      colder


Previous Comments:
------------------------------------------------------------------------

[2009-07-29 22:57:40] seva dot lapsha at gmail dot com

Line 6:
x This causes append to happen twice:
should be read as
* This causes rewind to happen twice:)

------------------------------------------------------------------------

[2009-07-29 22:54:19] seva dot lapsha at gmail dot com

Description:
------------
AppendIterator::append($iterator) calls $iterator->rewind() with no
reason.

This causes append to happen twice:

1) when $iterator appended;
2) when $iterator starts iterating.



Reproduce code:
---------------
<?php
class ArrayIterator1 extends ArrayIterator {
	function rewind() {
		echo ".";
		parent::rewind();
	}
}

$i1 = new ArrayIterator1(array(1, 2, 3));
$i2 = new ArrayIterator1(array(4, 5, 6));

$i = new AppendIterator();
$i->append($i1);
$i->append($i2);

foreach ($i as $n) {
	echo $n;
}
?>

Expected result:
----------------
.123.456

rewind() of each append()ed iterator should be called on demand when
iterating and not when append()ing.

Actual result:
--------------
..123.456

On each append() each append()ed iterator's rewind is called with no
need.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49104&edit=1



Thread (6 messages)

« previous php.bugs (#140580) next »