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