1--TEST--
2Test fflush() function: usage variations - files in different modes
3--SKIPIF--
4<?php
5if( substr(PHP_OS, 0, 3) != "WIN" )
6  die("skip.. only for Windows");
7?>
8--FILE--
9<?php
10/*  Prototype: bool fflush ( resource $handle );
11    Description: Flushes the output to a file
12*/
13
14/* test fflush() with handle to the files opened in different modes */
15
16$file_path = __DIR__;
17require $file_path.'/file.inc';
18
19echo "*** Testing fflush(): with various types of files ***\n";
20$file_types = array("empty", "numeric", "text", "text_with_new_line", "alphanumeric");
21$file_modes = array("w", "wb", "wt", "w+", "w+b", "w+t",
22                    "a", "ab", "at", "a+","a+b", "a+t",
23                    "x", "xb", "xt", "x+", "x+b", "x+t");
24
25$file_name = "$file_path/fflush_variation私はガラスを食べられます1.tmp";
26
27$count = 1;
28
29foreach( $file_types as $type ) {
30  echo "-- Iteration $count with file containing $type Data--\n";
31  foreach( $file_modes as $mode ) {
32    echo "-- File opened in $mode mode --\n";
33
34    // creating the file except for x mode
35    if( substr($mode, 0, 1) != "x" ) {
36      $file_handle = fopen($file_name, "w");
37      if($file_handle == false)
38        exit("Error:failed to open file $file_name");
39
40      // filling the file some data if mode is append mode
41      if( substr($mode, 0, 1) == "a")
42        fill_file($file_handle, $type, 10);
43      fclose($file_handle);
44    }
45
46    // opening the file in different modes
47    $file_handle = fopen($file_name, $mode);
48    if($file_handle == false)
49      exit("Error:failed to open file $file_name");
50
51    // writing data to the file
52    var_dump( fill_file($file_handle, $type, 50) );
53    var_dump( fflush($file_handle) );
54    fclose($file_handle);
55
56    // reading the contents of the file after flushing
57     var_dump( readfile($file_name) );
58     unlink($file_name);
59  }
60  $count++;
61}
62
63echo "\n*** Done ***";
64?>
65--EXPECT--
66*** Testing fflush(): with various types of files ***
67-- Iteration 1 with file containing empty Data--
68-- File opened in w mode --
69bool(true)
70bool(true)
71int(0)
72-- File opened in wb mode --
73bool(true)
74bool(true)
75int(0)
76-- File opened in wt mode --
77bool(true)
78bool(true)
79int(0)
80-- File opened in w+ mode --
81bool(true)
82bool(true)
83int(0)
84-- File opened in w+b mode --
85bool(true)
86bool(true)
87int(0)
88-- File opened in w+t mode --
89bool(true)
90bool(true)
91int(0)
92-- File opened in a mode --
93bool(true)
94bool(true)
95int(0)
96-- File opened in ab mode --
97bool(true)
98bool(true)
99int(0)
100-- File opened in at mode --
101bool(true)
102bool(true)
103int(0)
104-- File opened in a+ mode --
105bool(true)
106bool(true)
107int(0)
108-- File opened in a+b mode --
109bool(true)
110bool(true)
111int(0)
112-- File opened in a+t mode --
113bool(true)
114bool(true)
115int(0)
116-- File opened in x mode --
117bool(true)
118bool(true)
119int(0)
120-- File opened in xb mode --
121bool(true)
122bool(true)
123int(0)
124-- File opened in xt mode --
125bool(true)
126bool(true)
127int(0)
128-- File opened in x+ mode --
129bool(true)
130bool(true)
131int(0)
132-- File opened in x+b mode --
133bool(true)
134bool(true)
135int(0)
136-- File opened in x+t mode --
137bool(true)
138bool(true)
139int(0)
140-- Iteration 2 with file containing numeric Data--
141-- File opened in w mode --
142bool(true)
143bool(true)
14422222222222222222222222222222222222222222222222222int(50)
145-- File opened in wb mode --
146bool(true)
147bool(true)
14822222222222222222222222222222222222222222222222222int(50)
149-- File opened in wt mode --
150bool(true)
151bool(true)
15222222222222222222222222222222222222222222222222222int(50)
153-- File opened in w+ mode --
154bool(true)
155bool(true)
15622222222222222222222222222222222222222222222222222int(50)
157-- File opened in w+b mode --
158bool(true)
159bool(true)
16022222222222222222222222222222222222222222222222222int(50)
161-- File opened in w+t mode --
162bool(true)
163bool(true)
16422222222222222222222222222222222222222222222222222int(50)
165-- File opened in a mode --
166bool(true)
167bool(true)
168222222222222222222222222222222222222222222222222222222222222int(60)
169-- File opened in ab mode --
170bool(true)
171bool(true)
172222222222222222222222222222222222222222222222222222222222222int(60)
173-- File opened in at mode --
174bool(true)
175bool(true)
176222222222222222222222222222222222222222222222222222222222222int(60)
177-- File opened in a+ mode --
178bool(true)
179bool(true)
180222222222222222222222222222222222222222222222222222222222222int(60)
181-- File opened in a+b mode --
182bool(true)
183bool(true)
184222222222222222222222222222222222222222222222222222222222222int(60)
185-- File opened in a+t mode --
186bool(true)
187bool(true)
188222222222222222222222222222222222222222222222222222222222222int(60)
189-- File opened in x mode --
190bool(true)
191bool(true)
19222222222222222222222222222222222222222222222222222int(50)
193-- File opened in xb mode --
194bool(true)
195bool(true)
19622222222222222222222222222222222222222222222222222int(50)
197-- File opened in xt mode --
198bool(true)
199bool(true)
20022222222222222222222222222222222222222222222222222int(50)
201-- File opened in x+ mode --
202bool(true)
203bool(true)
20422222222222222222222222222222222222222222222222222int(50)
205-- File opened in x+b mode --
206bool(true)
207bool(true)
20822222222222222222222222222222222222222222222222222int(50)
209-- File opened in x+t mode --
210bool(true)
211bool(true)
21222222222222222222222222222222222222222222222222222int(50)
213-- Iteration 3 with file containing text Data--
214-- File opened in w mode --
215bool(true)
216bool(true)
217text text text text text text text text text text int(50)
218-- File opened in wb mode --
219bool(true)
220bool(true)
221text text text text text text text text text text int(50)
222-- File opened in wt mode --
223bool(true)
224bool(true)
225text text text text text text text text text text int(50)
226-- File opened in w+ mode --
227bool(true)
228bool(true)
229text text text text text text text text text text int(50)
230-- File opened in w+b mode --
231bool(true)
232bool(true)
233text text text text text text text text text text int(50)
234-- File opened in w+t mode --
235bool(true)
236bool(true)
237text text text text text text text text text text int(50)
238-- File opened in a mode --
239bool(true)
240bool(true)
241text text text text text text text text text text text text int(60)
242-- File opened in ab mode --
243bool(true)
244bool(true)
245text text text text text text text text text text text text int(60)
246-- File opened in at mode --
247bool(true)
248bool(true)
249text text text text text text text text text text text text int(60)
250-- File opened in a+ mode --
251bool(true)
252bool(true)
253text text text text text text text text text text text text int(60)
254-- File opened in a+b mode --
255bool(true)
256bool(true)
257text text text text text text text text text text text text int(60)
258-- File opened in a+t mode --
259bool(true)
260bool(true)
261text text text text text text text text text text text text int(60)
262-- File opened in x mode --
263bool(true)
264bool(true)
265text text text text text text text text text text int(50)
266-- File opened in xb mode --
267bool(true)
268bool(true)
269text text text text text text text text text text int(50)
270-- File opened in xt mode --
271bool(true)
272bool(true)
273text text text text text text text text text text int(50)
274-- File opened in x+ mode --
275bool(true)
276bool(true)
277text text text text text text text text text text int(50)
278-- File opened in x+b mode --
279bool(true)
280bool(true)
281text text text text text text text text text text int(50)
282-- File opened in x+t mode --
283bool(true)
284bool(true)
285text text text text text text text text text text int(50)
286-- Iteration 4 with file containing text_with_new_line Data--
287-- File opened in w mode --
288bool(true)
289bool(true)
290line
291line of text
292line
293line of text
294line
295line of tint(50)
296-- File opened in wb mode --
297bool(true)
298bool(true)
299line
300line of text
301line
302line of text
303line
304line of tint(50)
305-- File opened in wt mode --
306bool(true)
307bool(true)
308line
309line of text
310line
311line of text
312line
313line of tint(55)
314-- File opened in w+ mode --
315bool(true)
316bool(true)
317line
318line of text
319line
320line of text
321line
322line of tint(50)
323-- File opened in w+b mode --
324bool(true)
325bool(true)
326line
327line of text
328line
329line of text
330line
331line of tint(50)
332-- File opened in w+t mode --
333bool(true)
334bool(true)
335line
336line of text
337line
338line of text
339line
340line of tint(55)
341-- File opened in a mode --
342bool(true)
343bool(true)
344line
345line line
346line of text
347line
348line of text
349line
350line of tint(60)
351-- File opened in ab mode --
352bool(true)
353bool(true)
354line
355line line
356line of text
357line
358line of text
359line
360line of tint(60)
361-- File opened in at mode --
362bool(true)
363bool(true)
364line
365line line
366line of text
367line
368line of text
369line
370line of tint(65)
371-- File opened in a+ mode --
372bool(true)
373bool(true)
374line
375line line
376line of text
377line
378line of text
379line
380line of tint(60)
381-- File opened in a+b mode --
382bool(true)
383bool(true)
384line
385line line
386line of text
387line
388line of text
389line
390line of tint(60)
391-- File opened in a+t mode --
392bool(true)
393bool(true)
394line
395line line
396line of text
397line
398line of text
399line
400line of tint(65)
401-- File opened in x mode --
402bool(true)
403bool(true)
404line
405line of text
406line
407line of text
408line
409line of tint(50)
410-- File opened in xb mode --
411bool(true)
412bool(true)
413line
414line of text
415line
416line of text
417line
418line of tint(50)
419-- File opened in xt mode --
420bool(true)
421bool(true)
422line
423line of text
424line
425line of text
426line
427line of tint(55)
428-- File opened in x+ mode --
429bool(true)
430bool(true)
431line
432line of text
433line
434line of text
435line
436line of tint(50)
437-- File opened in x+b mode --
438bool(true)
439bool(true)
440line
441line of text
442line
443line of text
444line
445line of tint(50)
446-- File opened in x+t mode --
447bool(true)
448bool(true)
449line
450line of text
451line
452line of text
453line
454line of tint(55)
455-- Iteration 5 with file containing alphanumeric Data--
456-- File opened in w mode --
457bool(true)
458bool(true)
459ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
460-- File opened in wb mode --
461bool(true)
462bool(true)
463ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
464-- File opened in wt mode --
465bool(true)
466bool(true)
467ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
468-- File opened in w+ mode --
469bool(true)
470bool(true)
471ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
472-- File opened in w+b mode --
473bool(true)
474bool(true)
475ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
476-- File opened in w+t mode --
477bool(true)
478bool(true)
479ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
480-- File opened in a mode --
481bool(true)
482bool(true)
483ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
484-- File opened in ab mode --
485bool(true)
486bool(true)
487ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
488-- File opened in at mode --
489bool(true)
490bool(true)
491ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
492-- File opened in a+ mode --
493bool(true)
494bool(true)
495ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
496-- File opened in a+b mode --
497bool(true)
498bool(true)
499ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
500-- File opened in a+t mode --
501bool(true)
502bool(true)
503ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
504-- File opened in x mode --
505bool(true)
506bool(true)
507ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
508-- File opened in xb mode --
509bool(true)
510bool(true)
511ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
512-- File opened in xt mode --
513bool(true)
514bool(true)
515ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
516-- File opened in x+ mode --
517bool(true)
518bool(true)
519ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
520-- File opened in x+b mode --
521bool(true)
522bool(true)
523ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
524-- File opened in x+t mode --
525bool(true)
526bool(true)
527ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
528
529*** Done ***
530