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