php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53926 LimitIterator::rewind() problem
Submitted: 2011-02-04 18:47 UTC Modified: 2017-10-24 09:12 UTC
From: maciej at maciej-kaczmarek dot pl Assigned: salathe (profile)
Status: Assigned Package: SPL related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
46 - 32 = ?
Subscribe to this entry?

 
 [2011-02-04 18:47 UTC] maciej at maciej-kaczmarek dot pl
Description:
------------
When you using LimitIterator with offset that is larger or equal than inner 
iterator collection size and you invoke rewind() on LimitIterator then you get 
out of bounds exception.

You can solve that problem by handle exception from inner iterator's rewind() in 
LimitIterator::rewind()

Test script:
---------------
<?php
$some_array = array('foo', 'bar');
$iter = new ArrayIterator($some_array);
$limitIter = new LimitIterator($iter, 2);

foreach($limitIter as $value) {
    echo $value;
}

echo 'OK';
?>

Expected result:
----------------
only 'OK'

Actual result:
--------------
PHP Fatal error:  Uncaught exception 'OutOfBoundsException' with message 'Seek 
position 2 is out of range' in index.php:6

Stack trace:
#0 [internal function]: ArrayIterator->seek(2)
#1 index.php(6): LimitIterator->rewind()
#2 {main}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-08 17:45 UTC] cataphract@php.net
-Type: Bug +Type: Documentation Problem
 [2011-02-08 17:47 UTC] cataphract@php.net
I'm posting this on pastebin due to some objections of the bug tracker:

http://pastebin.com/S1wSfFh3
 [2012-04-27 23:20 UTC] salathe@php.net
-Assigned To: +Assigned To: salathe
 [2017-10-24 07:58 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: salathe +Assigned To:
 [2017-10-24 09:13 UTC] salathe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: salathe
 [2017-10-24 09:13 UTC] salathe@php.net
Re-assigning to me to keep visibility.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC