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