xref: /PHP-8.0/ext/spl/tests/iterator_032.phpt (revision f8d79582)
1--TEST--
2SPL: LimitIterator::getPosition()
3--FILE--
4<?php
5
6$it = new LimitIterator(new ArrayIterator(array(1,2,3,4)), 1, 2);
7
8foreach($it as $k=>$v)
9{
10    echo "$k=>$v\n";
11    var_dump($it->getPosition());
12}
13
14try
15{
16    $it->seek(0);
17}
18catch(OutOfBoundsException $e)
19{
20    echo $e->getMessage() . "\n";
21}
22
23$it->seek(2);
24var_dump($it->current());
25
26try
27{
28    $it->seek(3);
29}
30catch(OutOfBoundsException $e)
31{
32    echo $e->getMessage() . "\n";
33}
34
35$it->next();
36var_dump($it->valid());
37
38?>
39--EXPECT--
401=>2
41int(1)
422=>3
43int(2)
44Cannot seek to 0 which is below the offset 1
45int(3)
46Cannot seek to 3 which is behind offset 1 plus count 2
47bool(false)
48