1--TEST--
2Test fflush() function: usage variations - file opened in read-only mode
3--FILE--
4<?php
5/*  Prototype: bool fflush ( resource $handle );
6    Description: Flushes the output to a file
7*/
8
9/* test fflush() with handle to a file opened in read-only mode as resource */
10
11$file_path = dirname(__FILE__);
12require $file_path.'/file.inc';
13
14echo "*** Testing fflush(): with file handles of files opened in various read modes ***\n";
15$file_modes = array("r", "rb", "rt");
16
17$file_name = "$file_path/fflush_variation4.tmp";
18
19$count = 1;
20
21foreach( $file_modes as $mode ) {
22  echo "-- Iteration $count with file opened in $mode mode --\n";
23
24  // creating a file
25  $file_handle = fopen($file_name, "w");
26  if($file_handle == false)
27    exit("Error:failed to open file $file_name");
28  fclose($file_handle);
29
30  // opening the file in different read modes
31  $file_handle = fopen($file_name, $mode);
32  if($file_handle == false)
33    exit("Error:failed to open file $file_name");
34  var_dump( fflush($file_handle) );
35  fclose($file_handle);
36
37  unlink($file_name);
38  $count++;
39}
40
41echo "\n*** Done ***";
42?>
43--EXPECTF--
44*** Testing fflush(): with file handles of files opened in various read modes ***
45-- Iteration 1 with file opened in r mode --
46bool(true)
47-- Iteration 2 with file opened in rb mode --
48bool(true)
49-- Iteration 3 with file opened in rt mode --
50bool(true)
51
52*** Done ***
53