1--TEST--
2Test fscanf() function: usage variations - octal formats with float values
3--FILE--
4<?php
5
6/* Test fscanf() to scan float values using different octal format types */
7
8$file_path = __DIR__;
9
10echo "*** Test fscanf(): different octal format types with float values ***\n";
11
12// create a file
13$filename = "$file_path/fscanf_variation28.tmp";
14$file_handle = fopen($filename, "w");
15if($file_handle == false)
16  exit("Error:failed to open file $filename");
17
18// array of float type values
19
20$float_values = array (
21  -2147483649,
22  2147483648,
23  -0x80000001, // float value, beyond max negative int
24  0x800000001, // float value, beyond max positive int
25  020000000001, // float value, beyond max positive int
26  -020000000001, // float value, beyond max negative int
27  0.0,
28  -0.1,
29  1.0,
30  1e5,
31  -1e6,
32  1E8,
33  -1E9,
34  10.0000000000000000005,
35  10.5e+5
36);
37
38$octal_formats = array( "%o",
39                        "%ho", "%lo", "%Lo",
40                        " %o", "%o ", "% o",
41                        "\t%o", "\n%o", "%4o",
42                        "%30o", "%[0-7]", "%*o"
43                 );
44
45$counter = 1;
46
47// writing to the file
48foreach($float_values as $value) {
49  @fprintf($file_handle, $value);
50  @fprintf($file_handle, "\n");
51}
52// closing the file
53fclose($file_handle);
54
55// opening the file for reading
56$file_handle = fopen($filename, "r");
57if($file_handle == false) {
58  exit("Error:failed to open file $filename");
59}
60
61$counter = 1;
62// reading the values from file using different octal formats
63foreach($octal_formats as $octal_format) {
64  // rewind the file so that for every foreach iteration the file pointer starts from bof
65  rewind($file_handle);
66  echo "\n-- iteration $counter --\n";
67  while( !feof($file_handle) ) {
68    try {
69      var_dump(fscanf($file_handle,$octal_format));
70    } catch (ValueError $exception) {
71      echo $exception->getMessage() . "\n";
72    }
73  }
74  $counter++;
75}
76
77echo "\n*** Done ***";
78?>
79--CLEAN--
80<?php
81$file_path = __DIR__;
82$filename = "$file_path/fscanf_variation28.tmp";
83unlink($filename);
84?>
85--EXPECT--
86*** Test fscanf(): different octal format types with float values ***
87
88-- iteration 1 --
89array(1) {
90  [0]=>
91  int(-9020)
92}
93array(1) {
94  [0]=>
95  int(9020)
96}
97array(1) {
98  [0]=>
99  int(-9020)
100}
101array(1) {
102  [0]=>
103  int(1821)
104}
105array(1) {
106  [0]=>
107  int(9020)
108}
109array(1) {
110  [0]=>
111  int(-9020)
112}
113array(1) {
114  [0]=>
115  int(0)
116}
117array(1) {
118  [0]=>
119  int(0)
120}
121array(1) {
122  [0]=>
123  int(1)
124}
125array(1) {
126  [0]=>
127  int(32768)
128}
129array(1) {
130  [0]=>
131  int(-262144)
132}
133array(1) {
134  [0]=>
135  int(16777216)
136}
137array(1) {
138  [0]=>
139  int(-134217728)
140}
141array(1) {
142  [0]=>
143  int(8)
144}
145array(1) {
146  [0]=>
147  int(282624)
148}
149bool(false)
150
151-- iteration 2 --
152array(1) {
153  [0]=>
154  int(-9020)
155}
156array(1) {
157  [0]=>
158  int(9020)
159}
160array(1) {
161  [0]=>
162  int(-9020)
163}
164array(1) {
165  [0]=>
166  int(1821)
167}
168array(1) {
169  [0]=>
170  int(9020)
171}
172array(1) {
173  [0]=>
174  int(-9020)
175}
176array(1) {
177  [0]=>
178  int(0)
179}
180array(1) {
181  [0]=>
182  int(0)
183}
184array(1) {
185  [0]=>
186  int(1)
187}
188array(1) {
189  [0]=>
190  int(32768)
191}
192array(1) {
193  [0]=>
194  int(-262144)
195}
196array(1) {
197  [0]=>
198  int(16777216)
199}
200array(1) {
201  [0]=>
202  int(-134217728)
203}
204array(1) {
205  [0]=>
206  int(8)
207}
208array(1) {
209  [0]=>
210  int(282624)
211}
212bool(false)
213
214-- iteration 3 --
215array(1) {
216  [0]=>
217  int(-9020)
218}
219array(1) {
220  [0]=>
221  int(9020)
222}
223array(1) {
224  [0]=>
225  int(-9020)
226}
227array(1) {
228  [0]=>
229  int(1821)
230}
231array(1) {
232  [0]=>
233  int(9020)
234}
235array(1) {
236  [0]=>
237  int(-9020)
238}
239array(1) {
240  [0]=>
241  int(0)
242}
243array(1) {
244  [0]=>
245  int(0)
246}
247array(1) {
248  [0]=>
249  int(1)
250}
251array(1) {
252  [0]=>
253  int(32768)
254}
255array(1) {
256  [0]=>
257  int(-262144)
258}
259array(1) {
260  [0]=>
261  int(16777216)
262}
263array(1) {
264  [0]=>
265  int(-134217728)
266}
267array(1) {
268  [0]=>
269  int(8)
270}
271array(1) {
272  [0]=>
273  int(282624)
274}
275bool(false)
276
277-- iteration 4 --
278array(1) {
279  [0]=>
280  int(-9020)
281}
282array(1) {
283  [0]=>
284  int(9020)
285}
286array(1) {
287  [0]=>
288  int(-9020)
289}
290array(1) {
291  [0]=>
292  int(1821)
293}
294array(1) {
295  [0]=>
296  int(9020)
297}
298array(1) {
299  [0]=>
300  int(-9020)
301}
302array(1) {
303  [0]=>
304  int(0)
305}
306array(1) {
307  [0]=>
308  int(0)
309}
310array(1) {
311  [0]=>
312  int(1)
313}
314array(1) {
315  [0]=>
316  int(32768)
317}
318array(1) {
319  [0]=>
320  int(-262144)
321}
322array(1) {
323  [0]=>
324  int(16777216)
325}
326array(1) {
327  [0]=>
328  int(-134217728)
329}
330array(1) {
331  [0]=>
332  int(8)
333}
334array(1) {
335  [0]=>
336  int(282624)
337}
338bool(false)
339
340-- iteration 5 --
341array(1) {
342  [0]=>
343  int(-9020)
344}
345array(1) {
346  [0]=>
347  int(9020)
348}
349array(1) {
350  [0]=>
351  int(-9020)
352}
353array(1) {
354  [0]=>
355  int(1821)
356}
357array(1) {
358  [0]=>
359  int(9020)
360}
361array(1) {
362  [0]=>
363  int(-9020)
364}
365array(1) {
366  [0]=>
367  int(0)
368}
369array(1) {
370  [0]=>
371  int(0)
372}
373array(1) {
374  [0]=>
375  int(1)
376}
377array(1) {
378  [0]=>
379  int(32768)
380}
381array(1) {
382  [0]=>
383  int(-262144)
384}
385array(1) {
386  [0]=>
387  int(16777216)
388}
389array(1) {
390  [0]=>
391  int(-134217728)
392}
393array(1) {
394  [0]=>
395  int(8)
396}
397array(1) {
398  [0]=>
399  int(282624)
400}
401bool(false)
402
403-- iteration 6 --
404array(1) {
405  [0]=>
406  int(-9020)
407}
408array(1) {
409  [0]=>
410  int(9020)
411}
412array(1) {
413  [0]=>
414  int(-9020)
415}
416array(1) {
417  [0]=>
418  int(1821)
419}
420array(1) {
421  [0]=>
422  int(9020)
423}
424array(1) {
425  [0]=>
426  int(-9020)
427}
428array(1) {
429  [0]=>
430  int(0)
431}
432array(1) {
433  [0]=>
434  int(0)
435}
436array(1) {
437  [0]=>
438  int(1)
439}
440array(1) {
441  [0]=>
442  int(32768)
443}
444array(1) {
445  [0]=>
446  int(-262144)
447}
448array(1) {
449  [0]=>
450  int(16777216)
451}
452array(1) {
453  [0]=>
454  int(-134217728)
455}
456array(1) {
457  [0]=>
458  int(8)
459}
460array(1) {
461  [0]=>
462  int(282624)
463}
464bool(false)
465
466-- iteration 7 --
467Bad scan conversion character " "
468Bad scan conversion character " "
469Bad scan conversion character " "
470Bad scan conversion character " "
471Bad scan conversion character " "
472Bad scan conversion character " "
473Bad scan conversion character " "
474Bad scan conversion character " "
475Bad scan conversion character " "
476Bad scan conversion character " "
477Bad scan conversion character " "
478Bad scan conversion character " "
479Bad scan conversion character " "
480Bad scan conversion character " "
481Bad scan conversion character " "
482bool(false)
483
484-- iteration 8 --
485array(1) {
486  [0]=>
487  int(-9020)
488}
489array(1) {
490  [0]=>
491  int(9020)
492}
493array(1) {
494  [0]=>
495  int(-9020)
496}
497array(1) {
498  [0]=>
499  int(1821)
500}
501array(1) {
502  [0]=>
503  int(9020)
504}
505array(1) {
506  [0]=>
507  int(-9020)
508}
509array(1) {
510  [0]=>
511  int(0)
512}
513array(1) {
514  [0]=>
515  int(0)
516}
517array(1) {
518  [0]=>
519  int(1)
520}
521array(1) {
522  [0]=>
523  int(32768)
524}
525array(1) {
526  [0]=>
527  int(-262144)
528}
529array(1) {
530  [0]=>
531  int(16777216)
532}
533array(1) {
534  [0]=>
535  int(-134217728)
536}
537array(1) {
538  [0]=>
539  int(8)
540}
541array(1) {
542  [0]=>
543  int(282624)
544}
545bool(false)
546
547-- iteration 9 --
548array(1) {
549  [0]=>
550  int(-9020)
551}
552array(1) {
553  [0]=>
554  int(9020)
555}
556array(1) {
557  [0]=>
558  int(-9020)
559}
560array(1) {
561  [0]=>
562  int(1821)
563}
564array(1) {
565  [0]=>
566  int(9020)
567}
568array(1) {
569  [0]=>
570  int(-9020)
571}
572array(1) {
573  [0]=>
574  int(0)
575}
576array(1) {
577  [0]=>
578  int(0)
579}
580array(1) {
581  [0]=>
582  int(1)
583}
584array(1) {
585  [0]=>
586  int(32768)
587}
588array(1) {
589  [0]=>
590  int(-262144)
591}
592array(1) {
593  [0]=>
594  int(16777216)
595}
596array(1) {
597  [0]=>
598  int(-134217728)
599}
600array(1) {
601  [0]=>
602  int(8)
603}
604array(1) {
605  [0]=>
606  int(282624)
607}
608bool(false)
609
610-- iteration 10 --
611array(1) {
612  [0]=>
613  int(-140)
614}
615array(1) {
616  [0]=>
617  int(1127)
618}
619array(1) {
620  [0]=>
621  int(-140)
622}
623array(1) {
624  [0]=>
625  int(1821)
626}
627array(1) {
628  [0]=>
629  int(1127)
630}
631array(1) {
632  [0]=>
633  int(-140)
634}
635array(1) {
636  [0]=>
637  int(0)
638}
639array(1) {
640  [0]=>
641  int(0)
642}
643array(1) {
644  [0]=>
645  int(1)
646}
647array(1) {
648  [0]=>
649  int(512)
650}
651array(1) {
652  [0]=>
653  int(-64)
654}
655array(1) {
656  [0]=>
657  int(512)
658}
659array(1) {
660  [0]=>
661  int(-64)
662}
663array(1) {
664  [0]=>
665  int(8)
666}
667array(1) {
668  [0]=>
669  int(552)
670}
671bool(false)
672
673-- iteration 11 --
674array(1) {
675  [0]=>
676  int(-9020)
677}
678array(1) {
679  [0]=>
680  int(9020)
681}
682array(1) {
683  [0]=>
684  int(-9020)
685}
686array(1) {
687  [0]=>
688  int(1821)
689}
690array(1) {
691  [0]=>
692  int(9020)
693}
694array(1) {
695  [0]=>
696  int(-9020)
697}
698array(1) {
699  [0]=>
700  int(0)
701}
702array(1) {
703  [0]=>
704  int(0)
705}
706array(1) {
707  [0]=>
708  int(1)
709}
710array(1) {
711  [0]=>
712  int(32768)
713}
714array(1) {
715  [0]=>
716  int(-262144)
717}
718array(1) {
719  [0]=>
720  int(16777216)
721}
722array(1) {
723  [0]=>
724  int(-134217728)
725}
726array(1) {
727  [0]=>
728  int(8)
729}
730array(1) {
731  [0]=>
732  int(282624)
733}
734bool(false)
735
736-- iteration 12 --
737array(1) {
738  [0]=>
739  NULL
740}
741array(1) {
742  [0]=>
743  string(5) "21474"
744}
745array(1) {
746  [0]=>
747  NULL
748}
749array(1) {
750  [0]=>
751  string(4) "3435"
752}
753array(1) {
754  [0]=>
755  string(5) "21474"
756}
757array(1) {
758  [0]=>
759  NULL
760}
761array(1) {
762  [0]=>
763  string(1) "0"
764}
765array(1) {
766  [0]=>
767  NULL
768}
769array(1) {
770  [0]=>
771  string(1) "1"
772}
773array(1) {
774  [0]=>
775  string(6) "100000"
776}
777array(1) {
778  [0]=>
779  NULL
780}
781array(1) {
782  [0]=>
783  string(9) "100000000"
784}
785array(1) {
786  [0]=>
787  NULL
788}
789array(1) {
790  [0]=>
791  string(2) "10"
792}
793array(1) {
794  [0]=>
795  string(7) "1050000"
796}
797bool(false)
798
799-- iteration 13 --
800array(0) {
801}
802array(0) {
803}
804array(0) {
805}
806array(0) {
807}
808array(0) {
809}
810array(0) {
811}
812array(0) {
813}
814array(0) {
815}
816array(0) {
817}
818array(0) {
819}
820array(0) {
821}
822array(0) {
823}
824array(0) {
825}
826array(0) {
827}
828array(0) {
829}
830bool(false)
831
832*** Done ***
833