1--TEST--
2Test fscanf() function: usage variations - float formats with integer values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) {
6	die("skip this test is for 32bit platform only");
7}
8?>
9--FILE--
10<?php
11
12/*
13  Prototype: mixed fscanf ( resource $handle, string $format [, mixed &$...] );
14  Description: Parses input from a file according to a format
15*/
16
17/* Test fscanf() to scan integer values using different float format types */
18
19$file_path = dirname(__FILE__);
20
21echo "*** Test fscanf(): different float format types with integer values ***\n";
22
23// create a file
24$filename = "$file_path/fscanf_variation9.tmp";
25$file_handle = fopen($filename, "w");
26if($file_handle == false)
27  exit("Error:failed to open file $filename");
28
29// array of float type values
30
31$integer_values = array (
32  0,
33  1,
34  -1,
35  -2147483648, // max negative integer value
36  -2147483647,
37  2147483647,  // max positive integer value
38  2147483640,
39  0x123B,      // integer as hexadecimal
40  0x12ab,
41  0Xfff,
42  0XFA,
43  -0x80000000, // max negative integer as hexadecimal
44  0x7fffffff,  // max postive integer as hexadecimal
45  0x7FFFFFFF,  // max postive integer as hexadecimal
46  0123,        // integer as octal
47  01912,       // should be quivalent to octal 1
48  -020000000000, // max negative integer as octal
49  017777777777  // max positive integer as octal
50);
51
52$float_formats = array( "%f", "%hf", "%lf", "%Lf", " %f", "%f ", "% f", "\t%f", "\n%f", "%4f", "%30f", "%[0-9]", "%*f");
53
54$counter = 1;
55
56// writing to the file
57foreach($integer_values as $value) {
58  @fprintf($file_handle, $value);
59  @fprintf($file_handle, "\n");
60}
61// closing the file
62fclose($file_handle);
63
64// opening the file for reading
65$file_handle = fopen($filename, "r");
66if($file_handle == false) {
67  exit("Error:failed to open file $filename");
68}
69
70$counter = 1;
71// reading the values from file using different float formats
72foreach($float_formats as $float_format) {
73  // rewind the file so that for every foreach iteration the file pointer starts from bof
74  rewind($file_handle);
75  echo "\n-- iteration $counter --\n";
76  while( !feof($file_handle) ) {
77    var_dump( fscanf($file_handle,$float_format) );
78  }
79  $counter++;
80}
81
82echo "\n*** Done ***";
83?>
84--CLEAN--
85<?php
86$file_path = dirname(__FILE__);
87$filename = "$file_path/fscanf_variation9.tmp";
88unlink($filename);
89?>
90--EXPECTF--
91*** Test fscanf(): different float format types with integer values ***
92
93-- iteration 1 --
94array(1) {
95  [0]=>
96  float(0)
97}
98array(1) {
99  [0]=>
100  float(1)
101}
102array(1) {
103  [0]=>
104  float(-1)
105}
106array(1) {
107  [0]=>
108  float(-2147483648)
109}
110array(1) {
111  [0]=>
112  float(-2147483647)
113}
114array(1) {
115  [0]=>
116  float(2147483647)
117}
118array(1) {
119  [0]=>
120  float(2147483640)
121}
122array(1) {
123  [0]=>
124  float(4667)
125}
126array(1) {
127  [0]=>
128  float(4779)
129}
130array(1) {
131  [0]=>
132  float(4095)
133}
134array(1) {
135  [0]=>
136  float(250)
137}
138array(1) {
139  [0]=>
140  float(-2147483648)
141}
142array(1) {
143  [0]=>
144  float(2147483647)
145}
146array(1) {
147  [0]=>
148  float(2147483647)
149}
150array(1) {
151  [0]=>
152  float(83)
153}
154array(1) {
155  [0]=>
156  float(1)
157}
158array(1) {
159  [0]=>
160  float(-2147483648)
161}
162array(1) {
163  [0]=>
164  float(2147483647)
165}
166bool(false)
167
168-- iteration 2 --
169array(1) {
170  [0]=>
171  float(0)
172}
173array(1) {
174  [0]=>
175  float(1)
176}
177array(1) {
178  [0]=>
179  float(-1)
180}
181array(1) {
182  [0]=>
183  float(-2147483648)
184}
185array(1) {
186  [0]=>
187  float(-2147483647)
188}
189array(1) {
190  [0]=>
191  float(2147483647)
192}
193array(1) {
194  [0]=>
195  float(2147483640)
196}
197array(1) {
198  [0]=>
199  float(4667)
200}
201array(1) {
202  [0]=>
203  float(4779)
204}
205array(1) {
206  [0]=>
207  float(4095)
208}
209array(1) {
210  [0]=>
211  float(250)
212}
213array(1) {
214  [0]=>
215  float(-2147483648)
216}
217array(1) {
218  [0]=>
219  float(2147483647)
220}
221array(1) {
222  [0]=>
223  float(2147483647)
224}
225array(1) {
226  [0]=>
227  float(83)
228}
229array(1) {
230  [0]=>
231  float(1)
232}
233array(1) {
234  [0]=>
235  float(-2147483648)
236}
237array(1) {
238  [0]=>
239  float(2147483647)
240}
241bool(false)
242
243-- iteration 3 --
244array(1) {
245  [0]=>
246  float(0)
247}
248array(1) {
249  [0]=>
250  float(1)
251}
252array(1) {
253  [0]=>
254  float(-1)
255}
256array(1) {
257  [0]=>
258  float(-2147483648)
259}
260array(1) {
261  [0]=>
262  float(-2147483647)
263}
264array(1) {
265  [0]=>
266  float(2147483647)
267}
268array(1) {
269  [0]=>
270  float(2147483640)
271}
272array(1) {
273  [0]=>
274  float(4667)
275}
276array(1) {
277  [0]=>
278  float(4779)
279}
280array(1) {
281  [0]=>
282  float(4095)
283}
284array(1) {
285  [0]=>
286  float(250)
287}
288array(1) {
289  [0]=>
290  float(-2147483648)
291}
292array(1) {
293  [0]=>
294  float(2147483647)
295}
296array(1) {
297  [0]=>
298  float(2147483647)
299}
300array(1) {
301  [0]=>
302  float(83)
303}
304array(1) {
305  [0]=>
306  float(1)
307}
308array(1) {
309  [0]=>
310  float(-2147483648)
311}
312array(1) {
313  [0]=>
314  float(2147483647)
315}
316bool(false)
317
318-- iteration 4 --
319array(1) {
320  [0]=>
321  float(0)
322}
323array(1) {
324  [0]=>
325  float(1)
326}
327array(1) {
328  [0]=>
329  float(-1)
330}
331array(1) {
332  [0]=>
333  float(-2147483648)
334}
335array(1) {
336  [0]=>
337  float(-2147483647)
338}
339array(1) {
340  [0]=>
341  float(2147483647)
342}
343array(1) {
344  [0]=>
345  float(2147483640)
346}
347array(1) {
348  [0]=>
349  float(4667)
350}
351array(1) {
352  [0]=>
353  float(4779)
354}
355array(1) {
356  [0]=>
357  float(4095)
358}
359array(1) {
360  [0]=>
361  float(250)
362}
363array(1) {
364  [0]=>
365  float(-2147483648)
366}
367array(1) {
368  [0]=>
369  float(2147483647)
370}
371array(1) {
372  [0]=>
373  float(2147483647)
374}
375array(1) {
376  [0]=>
377  float(83)
378}
379array(1) {
380  [0]=>
381  float(1)
382}
383array(1) {
384  [0]=>
385  float(-2147483648)
386}
387array(1) {
388  [0]=>
389  float(2147483647)
390}
391bool(false)
392
393-- iteration 5 --
394array(1) {
395  [0]=>
396  float(0)
397}
398array(1) {
399  [0]=>
400  float(1)
401}
402array(1) {
403  [0]=>
404  float(-1)
405}
406array(1) {
407  [0]=>
408  float(-2147483648)
409}
410array(1) {
411  [0]=>
412  float(-2147483647)
413}
414array(1) {
415  [0]=>
416  float(2147483647)
417}
418array(1) {
419  [0]=>
420  float(2147483640)
421}
422array(1) {
423  [0]=>
424  float(4667)
425}
426array(1) {
427  [0]=>
428  float(4779)
429}
430array(1) {
431  [0]=>
432  float(4095)
433}
434array(1) {
435  [0]=>
436  float(250)
437}
438array(1) {
439  [0]=>
440  float(-2147483648)
441}
442array(1) {
443  [0]=>
444  float(2147483647)
445}
446array(1) {
447  [0]=>
448  float(2147483647)
449}
450array(1) {
451  [0]=>
452  float(83)
453}
454array(1) {
455  [0]=>
456  float(1)
457}
458array(1) {
459  [0]=>
460  float(-2147483648)
461}
462array(1) {
463  [0]=>
464  float(2147483647)
465}
466bool(false)
467
468-- iteration 6 --
469array(1) {
470  [0]=>
471  float(0)
472}
473array(1) {
474  [0]=>
475  float(1)
476}
477array(1) {
478  [0]=>
479  float(-1)
480}
481array(1) {
482  [0]=>
483  float(-2147483648)
484}
485array(1) {
486  [0]=>
487  float(-2147483647)
488}
489array(1) {
490  [0]=>
491  float(2147483647)
492}
493array(1) {
494  [0]=>
495  float(2147483640)
496}
497array(1) {
498  [0]=>
499  float(4667)
500}
501array(1) {
502  [0]=>
503  float(4779)
504}
505array(1) {
506  [0]=>
507  float(4095)
508}
509array(1) {
510  [0]=>
511  float(250)
512}
513array(1) {
514  [0]=>
515  float(-2147483648)
516}
517array(1) {
518  [0]=>
519  float(2147483647)
520}
521array(1) {
522  [0]=>
523  float(2147483647)
524}
525array(1) {
526  [0]=>
527  float(83)
528}
529array(1) {
530  [0]=>
531  float(1)
532}
533array(1) {
534  [0]=>
535  float(-2147483648)
536}
537array(1) {
538  [0]=>
539  float(2147483647)
540}
541bool(false)
542
543-- iteration 7 --
544
545Warning: fscanf(): Bad scan conversion character " " in %s on line %d
546NULL
547
548Warning: fscanf(): Bad scan conversion character " " in %s on line %d
549NULL
550
551Warning: fscanf(): Bad scan conversion character " " in %s on line %d
552NULL
553
554Warning: fscanf(): Bad scan conversion character " " in %s on line %d
555NULL
556
557Warning: fscanf(): Bad scan conversion character " " in %s on line %d
558NULL
559
560Warning: fscanf(): Bad scan conversion character " " in %s on line %d
561NULL
562
563Warning: fscanf(): Bad scan conversion character " " in %s on line %d
564NULL
565
566Warning: fscanf(): Bad scan conversion character " " in %s on line %d
567NULL
568
569Warning: fscanf(): Bad scan conversion character " " in %s on line %d
570NULL
571
572Warning: fscanf(): Bad scan conversion character " " in %s on line %d
573NULL
574
575Warning: fscanf(): Bad scan conversion character " " in %s on line %d
576NULL
577
578Warning: fscanf(): Bad scan conversion character " " in %s on line %d
579NULL
580
581Warning: fscanf(): Bad scan conversion character " " in %s on line %d
582NULL
583
584Warning: fscanf(): Bad scan conversion character " " in %s on line %d
585NULL
586
587Warning: fscanf(): Bad scan conversion character " " in %s on line %d
588NULL
589
590Warning: fscanf(): Bad scan conversion character " " in %s on line %d
591NULL
592
593Warning: fscanf(): Bad scan conversion character " " in %s on line %d
594NULL
595
596Warning: fscanf(): Bad scan conversion character " " in %s on line %d
597NULL
598bool(false)
599
600-- iteration 8 --
601array(1) {
602  [0]=>
603  float(0)
604}
605array(1) {
606  [0]=>
607  float(1)
608}
609array(1) {
610  [0]=>
611  float(-1)
612}
613array(1) {
614  [0]=>
615  float(-2147483648)
616}
617array(1) {
618  [0]=>
619  float(-2147483647)
620}
621array(1) {
622  [0]=>
623  float(2147483647)
624}
625array(1) {
626  [0]=>
627  float(2147483640)
628}
629array(1) {
630  [0]=>
631  float(4667)
632}
633array(1) {
634  [0]=>
635  float(4779)
636}
637array(1) {
638  [0]=>
639  float(4095)
640}
641array(1) {
642  [0]=>
643  float(250)
644}
645array(1) {
646  [0]=>
647  float(-2147483648)
648}
649array(1) {
650  [0]=>
651  float(2147483647)
652}
653array(1) {
654  [0]=>
655  float(2147483647)
656}
657array(1) {
658  [0]=>
659  float(83)
660}
661array(1) {
662  [0]=>
663  float(1)
664}
665array(1) {
666  [0]=>
667  float(-2147483648)
668}
669array(1) {
670  [0]=>
671  float(2147483647)
672}
673bool(false)
674
675-- iteration 9 --
676array(1) {
677  [0]=>
678  float(0)
679}
680array(1) {
681  [0]=>
682  float(1)
683}
684array(1) {
685  [0]=>
686  float(-1)
687}
688array(1) {
689  [0]=>
690  float(-2147483648)
691}
692array(1) {
693  [0]=>
694  float(-2147483647)
695}
696array(1) {
697  [0]=>
698  float(2147483647)
699}
700array(1) {
701  [0]=>
702  float(2147483640)
703}
704array(1) {
705  [0]=>
706  float(4667)
707}
708array(1) {
709  [0]=>
710  float(4779)
711}
712array(1) {
713  [0]=>
714  float(4095)
715}
716array(1) {
717  [0]=>
718  float(250)
719}
720array(1) {
721  [0]=>
722  float(-2147483648)
723}
724array(1) {
725  [0]=>
726  float(2147483647)
727}
728array(1) {
729  [0]=>
730  float(2147483647)
731}
732array(1) {
733  [0]=>
734  float(83)
735}
736array(1) {
737  [0]=>
738  float(1)
739}
740array(1) {
741  [0]=>
742  float(-2147483648)
743}
744array(1) {
745  [0]=>
746  float(2147483647)
747}
748bool(false)
749
750-- iteration 10 --
751array(1) {
752  [0]=>
753  float(0)
754}
755array(1) {
756  [0]=>
757  float(1)
758}
759array(1) {
760  [0]=>
761  float(-1)
762}
763array(1) {
764  [0]=>
765  float(-214)
766}
767array(1) {
768  [0]=>
769  float(-214)
770}
771array(1) {
772  [0]=>
773  float(2147)
774}
775array(1) {
776  [0]=>
777  float(2147)
778}
779array(1) {
780  [0]=>
781  float(4667)
782}
783array(1) {
784  [0]=>
785  float(4779)
786}
787array(1) {
788  [0]=>
789  float(4095)
790}
791array(1) {
792  [0]=>
793  float(250)
794}
795array(1) {
796  [0]=>
797  float(-214)
798}
799array(1) {
800  [0]=>
801  float(2147)
802}
803array(1) {
804  [0]=>
805  float(2147)
806}
807array(1) {
808  [0]=>
809  float(83)
810}
811array(1) {
812  [0]=>
813  float(1)
814}
815array(1) {
816  [0]=>
817  float(-214)
818}
819array(1) {
820  [0]=>
821  float(2147)
822}
823bool(false)
824
825-- iteration 11 --
826array(1) {
827  [0]=>
828  float(0)
829}
830array(1) {
831  [0]=>
832  float(1)
833}
834array(1) {
835  [0]=>
836  float(-1)
837}
838array(1) {
839  [0]=>
840  float(-2147483648)
841}
842array(1) {
843  [0]=>
844  float(-2147483647)
845}
846array(1) {
847  [0]=>
848  float(2147483647)
849}
850array(1) {
851  [0]=>
852  float(2147483640)
853}
854array(1) {
855  [0]=>
856  float(4667)
857}
858array(1) {
859  [0]=>
860  float(4779)
861}
862array(1) {
863  [0]=>
864  float(4095)
865}
866array(1) {
867  [0]=>
868  float(250)
869}
870array(1) {
871  [0]=>
872  float(-2147483648)
873}
874array(1) {
875  [0]=>
876  float(2147483647)
877}
878array(1) {
879  [0]=>
880  float(2147483647)
881}
882array(1) {
883  [0]=>
884  float(83)
885}
886array(1) {
887  [0]=>
888  float(1)
889}
890array(1) {
891  [0]=>
892  float(-2147483648)
893}
894array(1) {
895  [0]=>
896  float(2147483647)
897}
898bool(false)
899
900-- iteration 12 --
901array(1) {
902  [0]=>
903  string(1) "0"
904}
905array(1) {
906  [0]=>
907  string(1) "1"
908}
909array(1) {
910  [0]=>
911  NULL
912}
913array(1) {
914  [0]=>
915  NULL
916}
917array(1) {
918  [0]=>
919  NULL
920}
921array(1) {
922  [0]=>
923  string(10) "2147483647"
924}
925array(1) {
926  [0]=>
927  string(10) "2147483640"
928}
929array(1) {
930  [0]=>
931  string(4) "4667"
932}
933array(1) {
934  [0]=>
935  string(4) "4779"
936}
937array(1) {
938  [0]=>
939  string(4) "4095"
940}
941array(1) {
942  [0]=>
943  string(3) "250"
944}
945array(1) {
946  [0]=>
947  NULL
948}
949array(1) {
950  [0]=>
951  string(10) "2147483647"
952}
953array(1) {
954  [0]=>
955  string(10) "2147483647"
956}
957array(1) {
958  [0]=>
959  string(2) "83"
960}
961array(1) {
962  [0]=>
963  string(1) "1"
964}
965array(1) {
966  [0]=>
967  NULL
968}
969array(1) {
970  [0]=>
971  string(10) "2147483647"
972}
973bool(false)
974
975-- iteration 13 --
976array(0) {
977}
978array(0) {
979}
980array(0) {
981}
982array(0) {
983}
984array(0) {
985}
986array(0) {
987}
988array(0) {
989}
990array(0) {
991}
992array(0) {
993}
994array(0) {
995}
996array(0) {
997}
998array(0) {
999}
1000array(0) {
1001}
1002array(0) {
1003}
1004array(0) {
1005}
1006array(0) {
1007}
1008array(0) {
1009}
1010array(0) {
1011}
1012bool(false)
1013
1014*** Done ***
1015
1016