php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53119 LimitIterator(ArrayIterator)->seek() doesn't work correctly after OutOfBoundsE
Submitted: 2010-10-20 20:47 UTC Modified: 2021-08-13 14:36 UTC
From: marc-bennewitz at arcor dot de Assigned:
Status: Verified Package: SPL related
PHP Version: 5.3.3 OS: Linux
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:
13 - 2 = ?
Subscribe to this entry?

 
 [2010-10-20 20:47 UTC] marc-bennewitz at arcor dot de
Description:
------------
Seeking after an OutOfBoundException doesn't work without call of rewind.
With php < 5.3 it works as expected.

Test script:
---------------
$it = new ArrayIterator(array('zf9396', 'foo', null));
$it->rewind();

try {
    $it->seek(3);
} catch (OutOfBoundsException $e) {
    var_dump($it->key());
    $it->seek(0);
    var_dump($it->key());
}


$lit = new LimitIterator($it, 0, 10);
try {
    $lit->seek(3);
} catch (OutOfBoundsException $e) {
    var_dump($lit->key());
    $lit->seek(0);
    var_dump($lit->key());
}



Expected result:
----------------
NULL
int(0)
NULL
int(0)

Actual result:
--------------
NULL
int(0)
NULL
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-21 11:50 UTC] johannes@php.net
The exception leaves the iterator in undefined behavior. That is expected.
 [2010-10-21 18:22 UTC] marc-bennewitz at arcor dot de
The LimitIterator should have the same behavior as the inner iterator (in this example ArrayIterator) but on ArrayIterator there is no need to call rewind after an Exception.
 [2011-11-16 14:19 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: colder
 [2017-10-24 07:25 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: colder +Assigned To:
 [2018-08-18 13:56 UTC] cmb@php.net
> With php < 5.3 it works as expected.

Actually, with PHP < 5.2.14 and PHP < 5.3.3, respectively[1].

The behavioral change appears to have been introduced by fixing
bug #49723.

[1] <https://3v4l.org/9DrgU>
 [2021-08-13 14:36 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-08-13 14:36 UTC] cmb@php.net
Interestingly, calling ::rewind() instead of ::seek(0) works as
one would expect: <https://3v4l.org/PT2qW>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 15:01:30 2024 UTC