1--TEST--
2Test fgetc() function : usage variations - different read modes
3--FILE--
4<?php
5/* read from fie using fgetc, file opened using different
6   read read modes */
7
8echo "*** Testing fgetc() : usage variations ***\n";
9echo "-- Testing fgetc() with files opened with different read modes --\n";
10
11$file_modes = array( "a+", "a+b", "a+t",
12                     "x+", "x+b", "x+t",
13                     "w+", "w+b", "w+t" );
14
15$filename = __DIR__."/fgetc_variation4.tmp";
16foreach ($file_modes as $file_mode ) {
17  echo "-- File opened in mode : $file_mode --\n";
18
19  $file_handle = fopen($filename, $file_mode);
20  if(!$file_handle) {
21    echo "Error: failed to open file $filename!\n";
22    exit();
23  }
24  $data = "fgetc\n test";
25  fwrite($file_handle, $data);
26
27  // rewind the file pointer to beginning of the file
28  var_dump( rewind($file_handle) );
29  var_dump( ftell($file_handle) );
30  var_dump( feof($file_handle) );
31
32  // read from file, at least 7 chars
33  for($counter =0; $counter < 7; $counter ++) {
34    var_dump( fgetc($file_handle) ); // expected : 1 char
35    var_dump( ftell($file_handle) );
36    var_dump( feof($file_handle) ); // check if end of file pointer is set
37  }
38
39  // close the file
40  fclose($file_handle);
41
42  // delete the file
43  unlink($filename);
44}
45
46echo "Done\n";
47?>
48--EXPECT--
49 *** Testing fgetc() : usage variations ***
50-- Testing fgetc() with files opened with different read modes --
51-- File opened in mode : a+ --
52bool(true)
53int(0)
54bool(false)
55string(1) "f"
56int(1)
57bool(false)
58string(1) "g"
59int(2)
60bool(false)
61string(1) "e"
62int(3)
63bool(false)
64string(1) "t"
65int(4)
66bool(false)
67string(1) "c"
68int(5)
69bool(false)
70string(1) "
71"
72int(6)
73bool(false)
74string(1) " "
75int(7)
76bool(false)
77-- File opened in mode : a+b --
78bool(true)
79int(0)
80bool(false)
81string(1) "f"
82int(1)
83bool(false)
84string(1) "g"
85int(2)
86bool(false)
87string(1) "e"
88int(3)
89bool(false)
90string(1) "t"
91int(4)
92bool(false)
93string(1) "c"
94int(5)
95bool(false)
96string(1) "
97"
98int(6)
99bool(false)
100string(1) " "
101int(7)
102bool(false)
103-- File opened in mode : a+t --
104bool(true)
105int(0)
106bool(false)
107string(1) "f"
108int(1)
109bool(false)
110string(1) "g"
111int(2)
112bool(false)
113string(1) "e"
114int(3)
115bool(false)
116string(1) "t"
117int(4)
118bool(false)
119string(1) "c"
120int(5)
121bool(false)
122string(1) "
123"
124int(6)
125bool(false)
126string(1) " "
127int(7)
128bool(false)
129-- File opened in mode : x+ --
130bool(true)
131int(0)
132bool(false)
133string(1) "f"
134int(1)
135bool(false)
136string(1) "g"
137int(2)
138bool(false)
139string(1) "e"
140int(3)
141bool(false)
142string(1) "t"
143int(4)
144bool(false)
145string(1) "c"
146int(5)
147bool(false)
148string(1) "
149"
150int(6)
151bool(false)
152string(1) " "
153int(7)
154bool(false)
155-- File opened in mode : x+b --
156bool(true)
157int(0)
158bool(false)
159string(1) "f"
160int(1)
161bool(false)
162string(1) "g"
163int(2)
164bool(false)
165string(1) "e"
166int(3)
167bool(false)
168string(1) "t"
169int(4)
170bool(false)
171string(1) "c"
172int(5)
173bool(false)
174string(1) "
175"
176int(6)
177bool(false)
178string(1) " "
179int(7)
180bool(false)
181-- File opened in mode : x+t --
182bool(true)
183int(0)
184bool(false)
185string(1) "f"
186int(1)
187bool(false)
188string(1) "g"
189int(2)
190bool(false)
191string(1) "e"
192int(3)
193bool(false)
194string(1) "t"
195int(4)
196bool(false)
197string(1) "c"
198int(5)
199bool(false)
200string(1) "
201"
202int(6)
203bool(false)
204string(1) " "
205int(7)
206bool(false)
207-- File opened in mode : w+ --
208bool(true)
209int(0)
210bool(false)
211string(1) "f"
212int(1)
213bool(false)
214string(1) "g"
215int(2)
216bool(false)
217string(1) "e"
218int(3)
219bool(false)
220string(1) "t"
221int(4)
222bool(false)
223string(1) "c"
224int(5)
225bool(false)
226string(1) "
227"
228int(6)
229bool(false)
230string(1) " "
231int(7)
232bool(false)
233-- File opened in mode : w+b --
234bool(true)
235int(0)
236bool(false)
237string(1) "f"
238int(1)
239bool(false)
240string(1) "g"
241int(2)
242bool(false)
243string(1) "e"
244int(3)
245bool(false)
246string(1) "t"
247int(4)
248bool(false)
249string(1) "c"
250int(5)
251bool(false)
252string(1) "
253"
254int(6)
255bool(false)
256string(1) " "
257int(7)
258bool(false)
259-- File opened in mode : w+t --
260bool(true)
261int(0)
262bool(false)
263string(1) "f"
264int(1)
265bool(false)
266string(1) "g"
267int(2)
268bool(false)
269string(1) "e"
270int(3)
271bool(false)
272string(1) "t"
273int(4)
274bool(false)
275string(1) "c"
276int(5)
277bool(false)
278string(1) "
279"
280int(6)
281bool(false)
282string(1) " "
283int(7)
284bool(false)
285Done
286