xref: /PHP-7.3/ext/spl/tests/array_014.phpt (revision ded3d984)
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===DONE===
41<?php exit(0); ?>
42--EXPECT--
43int(11)
44int(5)
45int(4)
46Seek position -1 is out of range
47Seek position 12 is out of range
48int(0)
49int(1)
50int(2)
51int(3)
52int(4)
53int(5)
54int(6)
55int(7)
56int(8)
57int(9)
58int(10)
59===DONE===
60