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