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