#49723 [Fbk->Opn]: LimitIterator with empty ArrayIterator
| From: | goetas at lignano dot it | Date: | Fri, 02 Oct 2009 18:23:58 +0000 |
| Subject: | #49723 [Fbk->Opn]: LimitIterator with empty ArrayIterator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-143193@lists.php.net to get a copy of this message | ||
ID: 49723
User updated by: goetas at lignano dot it
Reported By: goetas at lignano dot it
-Status: Feedback
+Status: Open
Bug Type: SPL related
Operating System: *
PHP Version: 5.3.0
New Comment:
the problem is not resolved with php 5.3.2-dev on my apache2/winxp
Previous Comments:
------------------------------------------------------------------------
[2009-10-01 16:09:43] jani@php.net
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2009-09-30 13:48:01] goetas at lignano dot it
Description:
------------
iterating over an empty seekable iterator causes an unexpected
exception.
with actual implementation of LimitIterator::rewind() there is no way
to do an empty loop over an empty ArrayIterator.
i suggest this implementation for LimitIterator::rewind() method
function rewind(){
$this->it->rewind();
$this->pos = 0;
if($this->it->valid()){ // check for empty iterators
$this->seek($this->offset);
}
}
Reproduce code:
---------------
$it = new ArrayIterator(array());
$limIt = new LimitIterator($it, 0, 5);
foreach ($limIt as $item){
echo $item;
}
Expected result:
----------------
an empty loop
Actual result:
--------------
Uncaught exception 'OutOfBoundsException' with message 'Seek position 0
is out of range'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49723&edit=1