1--TEST--
2Test fscanf() function: usage variations - float formats with boolean
3--FILE--
4<?php
5
6/* Test fscanf() to scan boolean data using different float format types */
7
8$file_path = __DIR__;
9
10echo "*** Test fscanf(): different float format types with boolean data ***\n";
11
12// create a file
13$filename = "$file_path/fscanf_variation13.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$float_formats = array( "%f", "%hf", "%lf", "%Lf", " %f", "%f ", "% f", "\t%f", "\n%f", "%4f", "%30f", "%[0-9]", "%*f");
27
28$counter = 1;
29
30// writing to the file
31foreach($bool_types as $value) {
32  @fprintf($file_handle, $value);
33  @fprintf($file_handle, "\n");
34}
35// closing the file
36fclose($file_handle);
37
38// opening the file for reading
39$file_handle = fopen($filename, "r");
40if($file_handle == false) {
41  exit("Error:failed to open file $filename");
42}
43
44$counter = 1;
45// reading the values from file using different float formats
46foreach($float_formats as $float_format) {
47  // rewind the file so that for every foreach iteration the file pointer starts from bof
48  rewind($file_handle);
49  echo "\n-- iteration $counter --\n";
50  while( !feof($file_handle) ) {
51    try {
52      var_dump(fscanf($file_handle,$float_format));
53    } catch (ValueError $exception) {
54      echo $exception->getMessage() . "\n";
55    }
56  }
57  $counter++;
58}
59
60echo "\n*** Done ***";
61?>
62--CLEAN--
63<?php
64$file_path = __DIR__;
65$filename = "$file_path/fscanf_variation13.tmp";
66unlink($filename);
67?>
68--EXPECT--
69*** Test fscanf(): different float format types with boolean data ***
70
71-- iteration 1 --
72array(1) {
73  [0]=>
74  float(1)
75}
76NULL
77array(1) {
78  [0]=>
79  float(1)
80}
81NULL
82bool(false)
83
84-- iteration 2 --
85array(1) {
86  [0]=>
87  float(1)
88}
89NULL
90array(1) {
91  [0]=>
92  float(1)
93}
94NULL
95bool(false)
96
97-- iteration 3 --
98array(1) {
99  [0]=>
100  float(1)
101}
102NULL
103array(1) {
104  [0]=>
105  float(1)
106}
107NULL
108bool(false)
109
110-- iteration 4 --
111array(1) {
112  [0]=>
113  float(1)
114}
115NULL
116array(1) {
117  [0]=>
118  float(1)
119}
120NULL
121bool(false)
122
123-- iteration 5 --
124array(1) {
125  [0]=>
126  float(1)
127}
128NULL
129array(1) {
130  [0]=>
131  float(1)
132}
133NULL
134bool(false)
135
136-- iteration 6 --
137array(1) {
138  [0]=>
139  float(1)
140}
141NULL
142array(1) {
143  [0]=>
144  float(1)
145}
146NULL
147bool(false)
148
149-- iteration 7 --
150Bad scan conversion character " "
151Bad scan conversion character " "
152Bad scan conversion character " "
153Bad scan conversion character " "
154bool(false)
155
156-- iteration 8 --
157array(1) {
158  [0]=>
159  float(1)
160}
161NULL
162array(1) {
163  [0]=>
164  float(1)
165}
166NULL
167bool(false)
168
169-- iteration 9 --
170array(1) {
171  [0]=>
172  float(1)
173}
174NULL
175array(1) {
176  [0]=>
177  float(1)
178}
179NULL
180bool(false)
181
182-- iteration 10 --
183array(1) {
184  [0]=>
185  float(1)
186}
187NULL
188array(1) {
189  [0]=>
190  float(1)
191}
192NULL
193bool(false)
194
195-- iteration 11 --
196array(1) {
197  [0]=>
198  float(1)
199}
200NULL
201array(1) {
202  [0]=>
203  float(1)
204}
205NULL
206bool(false)
207
208-- iteration 12 --
209array(1) {
210  [0]=>
211  string(1) "1"
212}
213array(1) {
214  [0]=>
215  NULL
216}
217array(1) {
218  [0]=>
219  string(1) "1"
220}
221array(1) {
222  [0]=>
223  NULL
224}
225bool(false)
226
227-- iteration 13 --
228array(0) {
229}
230NULL
231array(0) {
232}
233NULL
234bool(false)
235
236*** Done ***
237