xref: /PHP-7.4/ext/spl/tests/fileobject_002.phpt (revision 26dfce7f)
1--TEST--
2SPL: SplFileObject::fgetc
3--FILE--
4<?php
5
6function test($name)
7{
8	echo "===$name===\n";
9
10	$o = new SplFileObject(__DIR__ . '/' . $name);
11
12	var_dump($o->key());
13	while(($c = $o->fgetc()) !== false)
14	{
15        // Kinda ugly but works around new lines mess
16        if ($c === "\r") {
17            continue;
18        }
19		var_dump($o->key(), $c, $o->eof());
20	}
21	echo "===EOF?===\n";
22	var_dump($o->eof());
23	var_dump($o->key());
24	var_dump($o->eof());
25}
26
27test('fileobject_001a.txt');
28test('fileobject_001b.txt');
29
30?>
31===DONE===
32<?php exit(0); ?>
33--EXPECT--
34===fileobject_001a.txt===
35int(0)
36int(0)
37string(1) "0"
38bool(false)
39int(1)
40string(1) "
41"
42bool(false)
43int(1)
44string(1) "1"
45bool(false)
46int(2)
47string(1) "
48"
49bool(false)
50int(2)
51string(1) "2"
52bool(false)
53int(3)
54string(1) "
55"
56bool(false)
57int(3)
58string(1) "3"
59bool(false)
60int(4)
61string(1) "
62"
63bool(false)
64int(4)
65string(1) "4"
66bool(false)
67int(5)
68string(1) "
69"
70bool(false)
71int(5)
72string(1) "5"
73bool(false)
74int(6)
75string(1) "
76"
77bool(false)
78===EOF?===
79bool(true)
80int(6)
81bool(true)
82===fileobject_001b.txt===
83int(0)
84int(0)
85string(1) "0"
86bool(false)
87int(1)
88string(1) "
89"
90bool(false)
91int(1)
92string(1) "1"
93bool(false)
94int(2)
95string(1) "
96"
97bool(false)
98int(2)
99string(1) "2"
100bool(false)
101int(3)
102string(1) "
103"
104bool(false)
105int(3)
106string(1) "3"
107bool(false)
108int(4)
109string(1) "
110"
111bool(false)
112int(4)
113string(1) "4"
114bool(false)
115int(5)
116string(1) "
117"
118bool(false)
119int(5)
120string(1) "5"
121bool(false)
122===EOF?===
123bool(true)
124int(5)
125bool(true)
126===DONE===
127