1--TEST--
2Test fgets() function : usage variations - read when file pointer at EOF
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip only valid for Windows');
7}
8?>
9--FILE--
10<?php
11/*
12 Prototype: string fgets ( resource $handle [, int $length] );
13 Description: Gets a line from file pointer
14*/
15
16// include the file.inc for common test funcitons
17include ("file.inc");
18
19$file_modes = array("w+", "w+b", "w+t",
20                    "a+", "a+b", "a+t",
21                    "x+", "x+b", "x+t");
22
23$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");
24
25echo "*** Testing fgets() : usage variations ***\n";
26
27$filename = __DIR__."/fgets_variation6.tmp";
28
29foreach($file_modes as $file_mode) {
30  echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";
31
32  foreach($file_content_types as $file_content_type) {
33    echo "-- File content type : $file_content_type --\n";
34
35    /* create files with $file_content_type */
36    $file_handle = fopen($filename, $file_mode);
37    $data = fill_file($file_handle, $file_content_type, 50);
38
39    if ( !$file_handle ) {
40      echo "Error: failed to open file $filename!";
41      exit();
42    }
43
44    echo "-- fgets() with file pointer pointing at EOF --\n";
45    // seek to end of the file and try fgets()
46    var_dump( fseek($file_handle, 0, SEEK_END) ); // set file pointer to eof
47    var_dump( ftell($file_handle) );  // ensure that file pointer is at eof
48    var_dump( feof($file_handle) );  // expected false
49
50    var_dump( fgets($file_handle) ); // try n read a line, none expected
51    var_dump( ftell($file_handle) ); // file pointer position
52    var_dump( feof($file_handle) ); // ensure that file pointer is at eof
53
54    //close file
55    fclose($file_handle);
56
57    // delete file
58    delete_file($filename);
59  } // file_content_type loop
60} // file_mode loop
61
62echo "Done\n";
63?>
64--EXPECT--
65*** Testing fgets() : usage variations ***
66
67-- Testing fgets() with file opened using mode w+ --
68-- File content type : numeric --
69-- fgets() with file pointer pointing at EOF --
70int(0)
71int(50)
72bool(false)
73bool(false)
74int(50)
75bool(true)
76-- File content type : text --
77-- fgets() with file pointer pointing at EOF --
78int(0)
79int(50)
80bool(false)
81bool(false)
82int(50)
83bool(true)
84-- File content type : text_with_new_line --
85-- fgets() with file pointer pointing at EOF --
86int(0)
87int(50)
88bool(false)
89bool(false)
90int(50)
91bool(true)
92-- File content type : alphanumeric --
93-- fgets() with file pointer pointing at EOF --
94int(0)
95int(50)
96bool(false)
97bool(false)
98int(50)
99bool(true)
100
101-- Testing fgets() with file opened using mode w+b --
102-- File content type : numeric --
103-- fgets() with file pointer pointing at EOF --
104int(0)
105int(50)
106bool(false)
107bool(false)
108int(50)
109bool(true)
110-- File content type : text --
111-- fgets() with file pointer pointing at EOF --
112int(0)
113int(50)
114bool(false)
115bool(false)
116int(50)
117bool(true)
118-- File content type : text_with_new_line --
119-- fgets() with file pointer pointing at EOF --
120int(0)
121int(50)
122bool(false)
123bool(false)
124int(50)
125bool(true)
126-- File content type : alphanumeric --
127-- fgets() with file pointer pointing at EOF --
128int(0)
129int(50)
130bool(false)
131bool(false)
132int(50)
133bool(true)
134
135-- Testing fgets() with file opened using mode w+t --
136-- File content type : numeric --
137-- fgets() with file pointer pointing at EOF --
138int(0)
139int(50)
140bool(false)
141bool(false)
142int(50)
143bool(true)
144-- File content type : text --
145-- fgets() with file pointer pointing at EOF --
146int(0)
147int(50)
148bool(false)
149bool(false)
150int(50)
151bool(true)
152-- File content type : text_with_new_line --
153-- fgets() with file pointer pointing at EOF --
154int(0)
155int(55)
156bool(false)
157bool(false)
158int(55)
159bool(true)
160-- File content type : alphanumeric --
161-- fgets() with file pointer pointing at EOF --
162int(0)
163int(50)
164bool(false)
165bool(false)
166int(50)
167bool(true)
168
169-- Testing fgets() with file opened using mode a+ --
170-- File content type : numeric --
171-- fgets() with file pointer pointing at EOF --
172int(0)
173int(50)
174bool(false)
175bool(false)
176int(50)
177bool(true)
178-- File content type : text --
179-- fgets() with file pointer pointing at EOF --
180int(0)
181int(50)
182bool(false)
183bool(false)
184int(50)
185bool(true)
186-- File content type : text_with_new_line --
187-- fgets() with file pointer pointing at EOF --
188int(0)
189int(50)
190bool(false)
191bool(false)
192int(50)
193bool(true)
194-- File content type : alphanumeric --
195-- fgets() with file pointer pointing at EOF --
196int(0)
197int(50)
198bool(false)
199bool(false)
200int(50)
201bool(true)
202
203-- Testing fgets() with file opened using mode a+b --
204-- File content type : numeric --
205-- fgets() with file pointer pointing at EOF --
206int(0)
207int(50)
208bool(false)
209bool(false)
210int(50)
211bool(true)
212-- File content type : text --
213-- fgets() with file pointer pointing at EOF --
214int(0)
215int(50)
216bool(false)
217bool(false)
218int(50)
219bool(true)
220-- File content type : text_with_new_line --
221-- fgets() with file pointer pointing at EOF --
222int(0)
223int(50)
224bool(false)
225bool(false)
226int(50)
227bool(true)
228-- File content type : alphanumeric --
229-- fgets() with file pointer pointing at EOF --
230int(0)
231int(50)
232bool(false)
233bool(false)
234int(50)
235bool(true)
236
237-- Testing fgets() with file opened using mode a+t --
238-- File content type : numeric --
239-- fgets() with file pointer pointing at EOF --
240int(0)
241int(50)
242bool(false)
243bool(false)
244int(50)
245bool(true)
246-- File content type : text --
247-- fgets() with file pointer pointing at EOF --
248int(0)
249int(50)
250bool(false)
251bool(false)
252int(50)
253bool(true)
254-- File content type : text_with_new_line --
255-- fgets() with file pointer pointing at EOF --
256int(0)
257int(55)
258bool(false)
259bool(false)
260int(55)
261bool(true)
262-- File content type : alphanumeric --
263-- fgets() with file pointer pointing at EOF --
264int(0)
265int(50)
266bool(false)
267bool(false)
268int(50)
269bool(true)
270
271-- Testing fgets() with file opened using mode x+ --
272-- File content type : numeric --
273-- fgets() with file pointer pointing at EOF --
274int(0)
275int(50)
276bool(false)
277bool(false)
278int(50)
279bool(true)
280-- File content type : text --
281-- fgets() with file pointer pointing at EOF --
282int(0)
283int(50)
284bool(false)
285bool(false)
286int(50)
287bool(true)
288-- File content type : text_with_new_line --
289-- fgets() with file pointer pointing at EOF --
290int(0)
291int(50)
292bool(false)
293bool(false)
294int(50)
295bool(true)
296-- File content type : alphanumeric --
297-- fgets() with file pointer pointing at EOF --
298int(0)
299int(50)
300bool(false)
301bool(false)
302int(50)
303bool(true)
304
305-- Testing fgets() with file opened using mode x+b --
306-- File content type : numeric --
307-- fgets() with file pointer pointing at EOF --
308int(0)
309int(50)
310bool(false)
311bool(false)
312int(50)
313bool(true)
314-- File content type : text --
315-- fgets() with file pointer pointing at EOF --
316int(0)
317int(50)
318bool(false)
319bool(false)
320int(50)
321bool(true)
322-- File content type : text_with_new_line --
323-- fgets() with file pointer pointing at EOF --
324int(0)
325int(50)
326bool(false)
327bool(false)
328int(50)
329bool(true)
330-- File content type : alphanumeric --
331-- fgets() with file pointer pointing at EOF --
332int(0)
333int(50)
334bool(false)
335bool(false)
336int(50)
337bool(true)
338
339-- Testing fgets() with file opened using mode x+t --
340-- File content type : numeric --
341-- fgets() with file pointer pointing at EOF --
342int(0)
343int(50)
344bool(false)
345bool(false)
346int(50)
347bool(true)
348-- File content type : text --
349-- fgets() with file pointer pointing at EOF --
350int(0)
351int(50)
352bool(false)
353bool(false)
354int(50)
355bool(true)
356-- File content type : text_with_new_line --
357-- fgets() with file pointer pointing at EOF --
358int(0)
359int(55)
360bool(false)
361bool(false)
362int(55)
363bool(true)
364-- File content type : alphanumeric --
365-- fgets() with file pointer pointing at EOF --
366int(0)
367int(50)
368bool(false)
369bool(false)
370int(50)
371bool(true)
372Done
373