1--TEST--
2Test sprintf() function : usage variations - octal 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/* Prototype  : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
12 * Description: Return a formatted string
13 * Source code: ext/standard/formatted_print.c
14*/
15
16echo "*** Testing sprintf() : octal formats with integer values ***\n";
17
18// array of integer values
19$integer_values = 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
40// array of octal formats
41$octal_formats = array(
42  "%o", "%ho", "%lo",
43  "%Lo", " %o", "%o ",
44  "\t%o", "\n%o", "%4o",
45  "%30o", "%[0-7]", "%*o"
46);
47
48$count = 1;
49foreach($integer_values as $integer_value) {
50  echo "\n-- Iteration $count --\n";
51
52  foreach($octal_formats as $format) {
53    var_dump( sprintf($format, $integer_value) );
54  }
55  $count++;
56};
57
58echo "Done";
59?>
60--EXPECT--
61*** Testing sprintf() : octal formats with integer values ***
62
63-- Iteration 1 --
64string(1) "0"
65string(1) "o"
66string(1) "0"
67string(1) "o"
68string(2) " 0"
69string(2) "0 "
70string(2) "	0"
71string(2) "
720"
73string(4) "   0"
74string(30) "                             0"
75string(4) "0-7]"
76string(1) "o"
77
78-- Iteration 2 --
79string(1) "1"
80string(1) "o"
81string(1) "1"
82string(1) "o"
83string(2) " 1"
84string(2) "1 "
85string(2) "	1"
86string(2) "
871"
88string(4) "   1"
89string(30) "                             1"
90string(4) "0-7]"
91string(1) "o"
92
93-- Iteration 3 --
94string(11) "37777777777"
95string(1) "o"
96string(11) "37777777777"
97string(1) "o"
98string(12) " 37777777777"
99string(12) "37777777777 "
100string(12) "	37777777777"
101string(12) "
10237777777777"
103string(11) "37777777777"
104string(30) "                   37777777777"
105string(4) "0-7]"
106string(1) "o"
107
108-- Iteration 4 --
109string(11) "20000000000"
110string(1) "o"
111string(11) "20000000000"
112string(1) "o"
113string(12) " 20000000000"
114string(12) "20000000000 "
115string(12) "	20000000000"
116string(12) "
11720000000000"
118string(11) "20000000000"
119string(30) "                   20000000000"
120string(4) "0-7]"
121string(1) "o"
122
123-- Iteration 5 --
124string(11) "20000000001"
125string(1) "o"
126string(11) "20000000001"
127string(1) "o"
128string(12) " 20000000001"
129string(12) "20000000001 "
130string(12) "	20000000001"
131string(12) "
13220000000001"
133string(11) "20000000001"
134string(30) "                   20000000001"
135string(4) "0-7]"
136string(1) "o"
137
138-- Iteration 6 --
139string(11) "17777777777"
140string(1) "o"
141string(11) "17777777777"
142string(1) "o"
143string(12) " 17777777777"
144string(12) "17777777777 "
145string(12) "	17777777777"
146string(12) "
14717777777777"
148string(11) "17777777777"
149string(30) "                   17777777777"
150string(4) "0-7]"
151string(1) "o"
152
153-- Iteration 7 --
154string(11) "17777777770"
155string(1) "o"
156string(11) "17777777770"
157string(1) "o"
158string(12) " 17777777770"
159string(12) "17777777770 "
160string(12) "	17777777770"
161string(12) "
16217777777770"
163string(11) "17777777770"
164string(30) "                   17777777770"
165string(4) "0-7]"
166string(1) "o"
167
168-- Iteration 8 --
169string(5) "11073"
170string(1) "o"
171string(5) "11073"
172string(1) "o"
173string(6) " 11073"
174string(6) "11073 "
175string(6) "	11073"
176string(6) "
17711073"
178string(5) "11073"
179string(30) "                         11073"
180string(4) "0-7]"
181string(1) "o"
182
183-- Iteration 9 --
184string(5) "11253"
185string(1) "o"
186string(5) "11253"
187string(1) "o"
188string(6) " 11253"
189string(6) "11253 "
190string(6) "	11253"
191string(6) "
19211253"
193string(5) "11253"
194string(30) "                         11253"
195string(4) "0-7]"
196string(1) "o"
197
198-- Iteration 10 --
199string(4) "7777"
200string(1) "o"
201string(4) "7777"
202string(1) "o"
203string(5) " 7777"
204string(5) "7777 "
205string(5) "	7777"
206string(5) "
2077777"
208string(4) "7777"
209string(30) "                          7777"
210string(4) "0-7]"
211string(1) "o"
212
213-- Iteration 11 --
214string(3) "372"
215string(1) "o"
216string(3) "372"
217string(1) "o"
218string(4) " 372"
219string(4) "372 "
220string(4) "	372"
221string(4) "
222372"
223string(4) " 372"
224string(30) "                           372"
225string(4) "0-7]"
226string(1) "o"
227
228-- Iteration 12 --
229string(11) "20000000000"
230string(1) "o"
231string(11) "20000000000"
232string(1) "o"
233string(12) " 20000000000"
234string(12) "20000000000 "
235string(12) "	20000000000"
236string(12) "
23720000000000"
238string(11) "20000000000"
239string(30) "                   20000000000"
240string(4) "0-7]"
241string(1) "o"
242
243-- Iteration 13 --
244string(11) "17777777777"
245string(1) "o"
246string(11) "17777777777"
247string(1) "o"
248string(12) " 17777777777"
249string(12) "17777777777 "
250string(12) "	17777777777"
251string(12) "
25217777777777"
253string(11) "17777777777"
254string(30) "                   17777777777"
255string(4) "0-7]"
256string(1) "o"
257
258-- Iteration 14 --
259string(11) "17777777777"
260string(1) "o"
261string(11) "17777777777"
262string(1) "o"
263string(12) " 17777777777"
264string(12) "17777777777 "
265string(12) "	17777777777"
266string(12) "
26717777777777"
268string(11) "17777777777"
269string(30) "                   17777777777"
270string(4) "0-7]"
271string(1) "o"
272
273-- Iteration 15 --
274string(3) "123"
275string(1) "o"
276string(3) "123"
277string(1) "o"
278string(4) " 123"
279string(4) "123 "
280string(4) "	123"
281string(4) "
282123"
283string(4) " 123"
284string(30) "                           123"
285string(4) "0-7]"
286string(1) "o"
287
288-- Iteration 16 --
289string(1) "1"
290string(1) "o"
291string(1) "1"
292string(1) "o"
293string(2) " 1"
294string(2) "1 "
295string(2) "	1"
296string(2) "
2971"
298string(4) "   1"
299string(30) "                             1"
300string(4) "0-7]"
301string(1) "o"
302
303-- Iteration 17 --
304string(11) "20000000000"
305string(1) "o"
306string(11) "20000000000"
307string(1) "o"
308string(12) " 20000000000"
309string(12) "20000000000 "
310string(12) "	20000000000"
311string(12) "
31220000000000"
313string(11) "20000000000"
314string(30) "                   20000000000"
315string(4) "0-7]"
316string(1) "o"
317
318-- Iteration 18 --
319string(11) "17777777777"
320string(1) "o"
321string(11) "17777777777"
322string(1) "o"
323string(12) " 17777777777"
324string(12) "17777777777 "
325string(12) "	17777777777"
326string(12) "
32717777777777"
328string(11) "17777777777"
329string(30) "                   17777777777"
330string(4) "0-7]"
331string(1) "o"
332Done
333