Edit report at http://bugs.php.net/bug.php?id=49723&edit=1
ID: 49723 Updated by: [email protected] Reported by: goetas at lignano dot it Summary: LimitIterator with empty ArrayIterator -Status: Assigned +Status: Closed Type: Bug Package: SPL related Operating System: * PHP Version: 5.3.0 Assigned To: colder New Comment: This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Fixed by removing unnecessary seeks Previous Comments: ------------------------------------------------------------------------ [2010-04-27 06:58:46] [email protected] Automatic comment from SVN on behalf of colder Revision: http://svn.php.net/viewvc/?view=revision&revision=298634 Log: Fix #49723 (Skip seek when unnecessary) ------------------------------------------------------------------------ [2010-04-27 06:57:50] [email protected] Automatic comment from SVN on behalf of colder Revision: http://svn.php.net/viewvc/?view=revision&revision=298633 Log: Fix #49723 (Skip seek when unnecessary) ------------------------------------------------------------------------ [2009-10-06 15:34:54] goetas at lignano dot it i think this can be a bug... or not correcty explained feature, becasue following code works fine: $it = new EmptyIterator(); // EmptyIterator instead of ArrayIterator $limIt = new LimitIterator($it, 0, 5); foreach ($limIt as $item){ echo $item; } both range are empty, but EmptyIterator does not implements SeekableIterator while ArrayIterator it does. exception is thrown only if iterator implements SeekableIterator and is empty. ------------------------------------------------------------------------ [2009-10-05 23:47:08] [email protected] The implementation you are looking at (defined in the php files) is an outdated illustration to show how the iterator is implemented, check out: spl_limit_it_seek() inside php-src/ext/spl/spl_iterators.c for the actual implementation. As for whether this is a bug or not, sounds expected behaviour to me that when trying to loop over an empty range it would cause an OutOfRangeException, rather check the iterator size before trying to loop. ------------------------------------------------------------------------ [2009-10-02 18:29:05] goetas at lignano dot it source code of LimitIterator, "seek" method at line 63: if ($this->it instanceof SeekableIterator) { $this->it->seek($position); <-- there is no check if i can move pointer to $position like on else branch $this->pos = $position; } else { while($this->pos < $position && $this->it->valid()) { <-- valid() ensures that i can move to $position $this->next(); } } ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=49723 -- Edit this bug report at http://bugs.php.net/bug.php?id=49723&edit=1
