xref: /PHP-8.0/ext/spl/tests/array_014.phpt (revision f8d79582)
1--TEST--
2SPL: ArrayIterator::seek()
3--FILE--
4<?php
5
6$it = new ArrayIterator(range(0,10));
7var_dump($it->count());
8$it->seek(5);
9var_dump($it->current());
10$it->seek(4);
11var_dump($it->current());
12try
13{
14    $it->seek(-1);
15    var_dump($it->current());
16}
17catch(Exception $e)
18{
19    echo $e->getMessage() . "\n";
20}
21
22try
23{
24    $it->seek(12);
25    var_dump($it->current());
26}
27catch(Exception $e)
28{
29    echo $e->getMessage() . "\n";
30}
31
32$pos = 0;
33foreach($it as $v)
34{
35    $it->seek($pos++);
36    var_dump($v);
37}
38
39?>
40--EXPECT--
41int(11)
42int(5)
43int(4)
44Seek position -1 is out of range
45Seek position 12 is out of range
46int(0)
47int(1)
48int(2)
49int(3)
50int(4)
51int(5)
52int(6)
53int(7)
54int(8)
55int(9)
56int(10)
57