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
 [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

Pull Requests

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 Nov 21 14:01:29 2024 UTC