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