1--TEST--
2Test fscanf() function: usage variations - file pointer pointing to EOF
3--FILE--
4<?php
5
6/* Test fscanf() to read a file when file pointer is pointing to EOF */
7
8$file_path = __DIR__;
9
10echo "*** Test fscanf(): to read a file when file pointer is pointing to EOF ***\n";
11
12// various formats
13$formats = array( "%d", "%f", "%e", "%u", " %s", "%x", "%o");
14
15$counter = 1;
16
17// various read modes
18$modes = array("r", "rb", "rt", "r+", "r+b", "r+t",
19               "w+", "w+b", "w+t",
20               "a+", "a+b", "a+t"
21         );
22
23$counter = 1;
24// reading the values from file using different integer formats
25foreach($modes as $mode) {
26
27  // create an empty file
28  $filename = "$file_path/fscanf_variation53.tmp";
29  $file_handle = fopen($filename, "w");
30  if($file_handle == false)
31    exit("Error:failed to open file $filename");
32
33  //writing data to the file
34  @fwrite($file_handle, "Sample text\n");
35
36  // writing a blank line
37  @fwrite($file_handle, "\n");
38
39  //closing the file
40  fclose($file_handle);
41
42  // opening file in $mode mode
43  $file_handle = fopen($filename, $mode);
44  if($file_handle == false) {
45    exit("Error:failed to open file $filename");
46  }
47  echo "\n-- iteration $counter --\n";
48
49  // current location
50  var_dump( ftell($file_handle) );
51
52  // set the file pointer to eof
53  var_dump( fseek($file_handle, 0, SEEK_END) );
54
55  // current location
56  var_dump( ftell($file_handle) );
57
58  foreach($formats as $format) {
59    var_dump( fscanf($file_handle,$format) );
60  }
61  $counter++;
62  fclose($file_handle);
63  unlink($filename);
64}
65
66echo "\n*** Done ***";
67?>
68--CLEAN--
69<?php
70$file_path = __DIR__;
71$filename = "$file_path/fscanf_variation53.tmp";
72if(file_exists($filename)) {
73  unlink($filename);
74}
75?>
76--EXPECT--
77*** Test fscanf(): to read a file when file pointer is pointing to EOF ***
78
79-- iteration 1 --
80int(0)
81int(0)
82int(13)
83bool(false)
84bool(false)
85bool(false)
86bool(false)
87bool(false)
88bool(false)
89bool(false)
90
91-- iteration 2 --
92int(0)
93int(0)
94int(13)
95bool(false)
96bool(false)
97bool(false)
98bool(false)
99bool(false)
100bool(false)
101bool(false)
102
103-- iteration 3 --
104int(0)
105int(0)
106int(13)
107bool(false)
108bool(false)
109bool(false)
110bool(false)
111bool(false)
112bool(false)
113bool(false)
114
115-- iteration 4 --
116int(0)
117int(0)
118int(13)
119bool(false)
120bool(false)
121bool(false)
122bool(false)
123bool(false)
124bool(false)
125bool(false)
126
127-- iteration 5 --
128int(0)
129int(0)
130int(13)
131bool(false)
132bool(false)
133bool(false)
134bool(false)
135bool(false)
136bool(false)
137bool(false)
138
139-- iteration 6 --
140int(0)
141int(0)
142int(13)
143bool(false)
144bool(false)
145bool(false)
146bool(false)
147bool(false)
148bool(false)
149bool(false)
150
151-- iteration 7 --
152int(0)
153int(0)
154int(0)
155bool(false)
156bool(false)
157bool(false)
158bool(false)
159bool(false)
160bool(false)
161bool(false)
162
163-- iteration 8 --
164int(0)
165int(0)
166int(0)
167bool(false)
168bool(false)
169bool(false)
170bool(false)
171bool(false)
172bool(false)
173bool(false)
174
175-- iteration 9 --
176int(0)
177int(0)
178int(0)
179bool(false)
180bool(false)
181bool(false)
182bool(false)
183bool(false)
184bool(false)
185bool(false)
186
187-- iteration 10 --
188int(0)
189int(0)
190int(13)
191bool(false)
192bool(false)
193bool(false)
194bool(false)
195bool(false)
196bool(false)
197bool(false)
198
199-- iteration 11 --
200int(0)
201int(0)
202int(13)
203bool(false)
204bool(false)
205bool(false)
206bool(false)
207bool(false)
208bool(false)
209bool(false)
210
211-- iteration 12 --
212int(0)
213int(0)
214int(13)
215bool(false)
216bool(false)
217bool(false)
218bool(false)
219bool(false)
220bool(false)
221bool(false)
222
223*** Done ***
224