1--TEST--
2Test sprintf() function : usage variations - octal formats with integer values
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
5--FILE--
6<?php
7echo "*** Testing sprintf() : octal formats with integer values ***\n";
8
9// array of integer values
10$integer_values = array(
11  0,
12  1,
13  -1,
14  -2147483648, // max negative integer value
15  -2147483647,
16  2147483647,  // max positive integer value
17  2147483640,
18  0x123B,      // integer as hexadecimal
19  0x12ab,
20  0Xfff,
21  0XFA,
22  -0x80000000, // max negative integer as hexadecimal
23  0x7fffffff,  // max positive integer as hexadecimal
24  0x7FFFFFFF,  // max positive integer as hexadecimal
25  0123,        // integer as octal
26  01,       // should be quivalent to octal 1
27  -020000000000, // max negative integer as octal
28  017777777777  // max positive integer as octal
29);
30
31// array of octal formats
32$octal_formats = array(
33  "%o", "%lo", " %o", "%o ",
34  "\t%o", "\n%o", "%4o", "%30o",
35);
36
37$count = 1;
38foreach($integer_values as $integer_value) {
39  echo "\n-- Iteration $count --\n";
40
41  foreach($octal_formats as $format) {
42    var_dump( sprintf($format, $integer_value) );
43  }
44  $count++;
45};
46
47echo "Done";
48?>
49--EXPECT--
50*** Testing sprintf() : octal formats with integer values ***
51
52-- Iteration 1 --
53string(1) "0"
54string(1) "0"
55string(2) " 0"
56string(2) "0 "
57string(2) "	0"
58string(2) "
590"
60string(4) "   0"
61string(30) "                             0"
62
63-- Iteration 2 --
64string(1) "1"
65string(1) "1"
66string(2) " 1"
67string(2) "1 "
68string(2) "	1"
69string(2) "
701"
71string(4) "   1"
72string(30) "                             1"
73
74-- Iteration 3 --
75string(22) "1777777777777777777777"
76string(22) "1777777777777777777777"
77string(23) " 1777777777777777777777"
78string(23) "1777777777777777777777 "
79string(23) "	1777777777777777777777"
80string(23) "
811777777777777777777777"
82string(22) "1777777777777777777777"
83string(30) "        1777777777777777777777"
84
85-- Iteration 4 --
86string(22) "1777777777760000000000"
87string(22) "1777777777760000000000"
88string(23) " 1777777777760000000000"
89string(23) "1777777777760000000000 "
90string(23) "	1777777777760000000000"
91string(23) "
921777777777760000000000"
93string(22) "1777777777760000000000"
94string(30) "        1777777777760000000000"
95
96-- Iteration 5 --
97string(22) "1777777777760000000001"
98string(22) "1777777777760000000001"
99string(23) " 1777777777760000000001"
100string(23) "1777777777760000000001 "
101string(23) "	1777777777760000000001"
102string(23) "
1031777777777760000000001"
104string(22) "1777777777760000000001"
105string(30) "        1777777777760000000001"
106
107-- Iteration 6 --
108string(11) "17777777777"
109string(11) "17777777777"
110string(12) " 17777777777"
111string(12) "17777777777 "
112string(12) "	17777777777"
113string(12) "
11417777777777"
115string(11) "17777777777"
116string(30) "                   17777777777"
117
118-- Iteration 7 --
119string(11) "17777777770"
120string(11) "17777777770"
121string(12) " 17777777770"
122string(12) "17777777770 "
123string(12) "	17777777770"
124string(12) "
12517777777770"
126string(11) "17777777770"
127string(30) "                   17777777770"
128
129-- Iteration 8 --
130string(5) "11073"
131string(5) "11073"
132string(6) " 11073"
133string(6) "11073 "
134string(6) "	11073"
135string(6) "
13611073"
137string(5) "11073"
138string(30) "                         11073"
139
140-- Iteration 9 --
141string(5) "11253"
142string(5) "11253"
143string(6) " 11253"
144string(6) "11253 "
145string(6) "	11253"
146string(6) "
14711253"
148string(5) "11253"
149string(30) "                         11253"
150
151-- Iteration 10 --
152string(4) "7777"
153string(4) "7777"
154string(5) " 7777"
155string(5) "7777 "
156string(5) "	7777"
157string(5) "
1587777"
159string(4) "7777"
160string(30) "                          7777"
161
162-- Iteration 11 --
163string(3) "372"
164string(3) "372"
165string(4) " 372"
166string(4) "372 "
167string(4) "	372"
168string(4) "
169372"
170string(4) " 372"
171string(30) "                           372"
172
173-- Iteration 12 --
174string(22) "1777777777760000000000"
175string(22) "1777777777760000000000"
176string(23) " 1777777777760000000000"
177string(23) "1777777777760000000000 "
178string(23) "	1777777777760000000000"
179string(23) "
1801777777777760000000000"
181string(22) "1777777777760000000000"
182string(30) "        1777777777760000000000"
183
184-- Iteration 13 --
185string(11) "17777777777"
186string(11) "17777777777"
187string(12) " 17777777777"
188string(12) "17777777777 "
189string(12) "	17777777777"
190string(12) "
19117777777777"
192string(11) "17777777777"
193string(30) "                   17777777777"
194
195-- Iteration 14 --
196string(11) "17777777777"
197string(11) "17777777777"
198string(12) " 17777777777"
199string(12) "17777777777 "
200string(12) "	17777777777"
201string(12) "
20217777777777"
203string(11) "17777777777"
204string(30) "                   17777777777"
205
206-- Iteration 15 --
207string(3) "123"
208string(3) "123"
209string(4) " 123"
210string(4) "123 "
211string(4) "	123"
212string(4) "
213123"
214string(4) " 123"
215string(30) "                           123"
216
217-- Iteration 16 --
218string(1) "1"
219string(1) "1"
220string(2) " 1"
221string(2) "1 "
222string(2) "	1"
223string(2) "
2241"
225string(4) "   1"
226string(30) "                             1"
227
228-- Iteration 17 --
229string(22) "1777777777760000000000"
230string(22) "1777777777760000000000"
231string(23) " 1777777777760000000000"
232string(23) "1777777777760000000000 "
233string(23) "	1777777777760000000000"
234string(23) "
2351777777777760000000000"
236string(22) "1777777777760000000000"
237string(30) "        1777777777760000000000"
238
239-- Iteration 18 --
240string(11) "17777777777"
241string(11) "17777777777"
242string(12) " 17777777777"
243string(12) "17777777777 "
244string(12) "	17777777777"
245string(12) "
24617777777777"
247string(11) "17777777777"
248string(30) "                   17777777777"
249Done
250