1--TEST--
2Test fgetc() function : usage variations - write only modes (Bug #42036)
3--FILE--
4<?php
5/*
6 Prototype: string fgetc ( resource $handle );
7 Description: Gets character from file pointer
8*/
9
10/* try fgetc on files which are opened in non readable modes
11    w, wb, wt,
12    a, ab, at,
13    x, xb, xt
14*/
15// include the header for common test function
16include ("file.inc");
17
18echo "*** Testing fgetc() with file opened in write only mode ***\n";
19
20$file_modes = array("w", "wb", "wt", "a", "ab", "at", "x", "xb", "xt");
21$filename = dirname(__FILE__)."/fgetc_variation3.tmp";
22foreach ($file_modes as $file_mode ) {
23  echo "-- File opened in mode : $file_mode --\n";
24
25  $file_handle = fopen($filename, $file_mode);
26  if(!$file_handle) {
27    echo "Error: failed to open file $filename!\n";
28    exit();
29  }
30  $data = "fgetc_variation test";
31  fwrite($file_handle, $data);
32
33  // rewind the file pointer to begining of the file
34  var_dump( rewind($file_handle) );
35  var_dump( ftell($file_handle) );
36  var_dump( feof($file_handle) );
37
38  // read from file
39  var_dump( fgetc($file_handle) ); // expected : no chars should be read
40  var_dump( ftell($file_handle) ); // ensure that file pointer position is not changed
41  var_dump( feof($file_handle) ); // check if end of file pointer is set
42
43  // close the file
44  fclose($file_handle);
45
46  // delete the file
47  unlink($filename);
48}
49
50echo "Done\n";
51?>
52--EXPECTF--
53*** Testing fgetc() with file opened in write only mode ***
54-- File opened in mode : w --
55bool(true)
56int(0)
57bool(false)
58bool(false)
59int(0)
60bool(false)
61-- File opened in mode : wb --
62bool(true)
63int(0)
64bool(false)
65bool(false)
66int(0)
67bool(false)
68-- File opened in mode : wt --
69bool(true)
70int(0)
71bool(false)
72bool(false)
73int(0)
74bool(false)
75-- File opened in mode : a --
76bool(true)
77int(0)
78bool(false)
79bool(false)
80int(0)
81bool(false)
82-- File opened in mode : ab --
83bool(true)
84int(0)
85bool(false)
86bool(false)
87int(0)
88bool(false)
89-- File opened in mode : at --
90bool(true)
91int(0)
92bool(false)
93bool(false)
94int(0)
95bool(false)
96-- File opened in mode : x --
97bool(true)
98int(0)
99bool(false)
100bool(false)
101int(0)
102bool(false)
103-- File opened in mode : xb --
104bool(true)
105int(0)
106bool(false)
107bool(false)
108int(0)
109bool(false)
110-- File opened in mode : xt --
111bool(true)
112int(0)
113bool(false)
114bool(false)
115int(0)
116bool(false)
117Done
118