xref: /PHP-8.0/ext/spl/tests/fileobject_001.phpt (revision 79a28324)
1--TEST--
2SPL: SplFileObject::seek'ing
3--FILE--
4<?php
5
6$o = new SplFileObject(__DIR__ . '/fileobject_001a.txt');
7
8var_dump($o->key());
9var_dump($o->current());
10$o->setFlags(SplFileObject::DROP_NEW_LINE);
11var_dump($o->key());
12var_dump($o->current());
13var_dump($o->key());
14$o->next();
15var_dump($o->key());
16var_dump($o->current());
17var_dump($o->key());
18$o->rewind();
19var_dump($o->key());
20var_dump($o->current());
21var_dump($o->key());
22$o->seek(4);
23var_dump($o->key());
24var_dump($o->current());
25var_dump($o->key());
26
27echo "===A===\n";
28foreach($o as $n => $l)
29{
30    var_dump($n, $l);
31}
32
33echo "===B===\n";
34$o = new SplFileObject(__DIR__ . '/fileobject_001b.txt');
35$o->setFlags(SplFileObject::DROP_NEW_LINE);
36foreach($o as $n => $l)
37{
38    var_dump($n, $l);
39}
40
41?>
42--EXPECTF--
43int(0)
44string(%d) "0
45"
46int(0)
47string(%d) "0
48"
49int(0)
50int(1)
51string(1) "1"
52int(1)
53int(0)
54string(1) "0"
55int(0)
56int(4)
57string(1) "4"
58int(4)
59===A===
60int(0)
61string(1) "0"
62int(1)
63string(1) "1"
64int(2)
65string(1) "2"
66int(3)
67string(1) "3"
68int(4)
69string(1) "4"
70int(5)
71string(1) "5"
72int(6)
73string(0) ""
74===B===
75int(0)
76string(1) "0"
77int(1)
78string(1) "1"
79int(2)
80string(1) "2"
81int(3)
82string(1) "3"
83int(4)
84string(1) "4"
85int(5)
86string(1) "5"
87