Edit report at https://bugs.php.net/bug.php?id=63508&edit=1

 ID:                 63508
 Updated by:         ni...@php.net
 Reported by:        le...@php.net
 Summary:            LimitIterator should implement SeekableIterator
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            SPL related
 PHP Version:        5.4.8
 Block user comment: N
 Private report:     N

 New Comment:

The LimitIterator::seek() method does not have the same functionality as the 
SeekableIterator::seek() method. The latter seeks to a certain offset in an 
iterator, whereas seeks to a certain offset in the *parent* iterator.

E.g. given this code:

<?php
$array = range(0, 9);
$it = new ArrayIterator($array);
$lim = new LimitIterator($it, 3, 4);
$lim->seek(3);
var_dump(iterator_to_array($lim));

The result will the numbers 3 to 6, rather than just 3+3 to 6 (i.e. just 6).

Also the limit iterator won't allow you to seek outside the range of the limit, 
e.g. you can't do $lim->seek(2) in the above example.

This behavior difference is rather unfortunate :/ But in its current form it 
can't implement the interface.


Previous Comments:
------------------------------------------------------------------------
[2012-11-14 06:05:59] le...@php.net

I just noticed something: LimitIterator::seek returns int; 
SeekableIterator::seek 
returns void;

When they were created they should have been made to match.  That's probably 
why 
LimitIterator didn't implement SeekableIterator, though.  

Is this a problem?

------------------------------------------------------------------------
[2012-11-13 23:08:35] le...@php.net

The following patch has been added/updated:

Patch Name: LimitIterator_implement_SeekableIterator
Revision:   1352848115
URL:        
https://bugs.php.net/patch-display.php?bug=63508&patch=LimitIterator_implement_SeekableIterator&revision=1352848115

------------------------------------------------------------------------
[2012-11-13 23:00:40] le...@php.net

The following patch has been added/updated:

Patch Name: LimitIterator_implement_SeekableIterator
Revision:   1352847640
URL:        
https://bugs.php.net/patch-display.php?bug=63508&patch=LimitIterator_implement_SeekableIterator&revision=1352847640

------------------------------------------------------------------------
[2012-11-13 23:00:18] le...@php.net

Description:
------------
LimitIterator already implements SeekableIterator; it just doesn't do so 
formally.

Test script:
---------------
<?php

$iterator = new LimitIterator(
    new ArrayIterator(array(1,2,3,4))
);

var_dump($iterator instanceof SeekableIterator);
var_dump(method_exists($iterator, 'seek'));

$iterator->seek(2);
var_dump($iterator->current());

Expected result:
----------------
bool(true)
bool(true)
int(3)

Actual result:
--------------
bool(false)
bool(true)
int(3)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63508&edit=1

Reply via email to