1--TEST--
2Test sprintf() function : usage variations - hexa 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
7/* Prototype  : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
8 * Description: Return a formatted string
9 * Source code: ext/standard/formatted_print.c
10*/
11
12echo "*** Testing sprintf() : hexa formats with integer values ***\n";
13
14// array of integer values
15$integer_values = array(
16  0,
17  1,
18  -1,
19  -2147483648, // max negative integer value
20  -2147483647,
21  2147483647,  // max positive integer value
22  2147483640,
23  0x123B,      // integer as hexadecimal
24  0x12ab,
25  0Xfff,
26  0XFA,
27  -0x80000000, // max negative integer as hexadecimal
28  0x7fffffff,  // max positive integer as hexadecimal
29  0x7FFFFFFF,  // max positive integer as hexadecimal
30  0123,        // integer as octal
31  01,       // should be quivalent to octal 1
32  -020000000000, // max negative integer as octal
33  017777777777  // max positive integer as octal
34);
35
36// array of hexa formats
37$hexa_formats = array(
38  "%x", "%xx", "%lx",
39  "%Lx", " %x", "%x ",
40  "\t%x", "\n%x", "%4x",
41  "%30x", "%[0-9A-Fa-f]", "%*x"
42);
43
44$count = 1;
45foreach($integer_values as $integer_value) {
46  echo "\n-- Iteration $count --\n";
47
48  foreach($hexa_formats as $format) {
49    var_dump( sprintf($format, $integer_value) );
50  }
51  $count++;
52};
53
54echo "Done";
55?>
56--EXPECTF--
57*** Testing sprintf() : hexa formats with integer values ***
58
59-- Iteration 1 --
60string(1) "0"
61string(2) "0x"
62string(1) "0"
63string(1) "x"
64string(2) " 0"
65string(2) "0 "
66string(2) "	0"
67string(2) "
680"
69string(4) "   0"
70string(30) "                             0"
71string(10) "0-9A-Fa-f]"
72string(1) "x"
73
74-- Iteration 2 --
75string(1) "1"
76string(2) "1x"
77string(1) "1"
78string(1) "x"
79string(2) " 1"
80string(2) "1 "
81string(2) "	1"
82string(2) "
831"
84string(4) "   1"
85string(30) "                             1"
86string(10) "0-9A-Fa-f]"
87string(1) "x"
88
89-- Iteration 3 --
90string(16) "ffffffffffffffff"
91string(17) "ffffffffffffffffx"
92string(16) "ffffffffffffffff"
93string(1) "x"
94string(17) " ffffffffffffffff"
95string(17) "ffffffffffffffff "
96string(17) "	ffffffffffffffff"
97string(17) "
98ffffffffffffffff"
99string(16) "ffffffffffffffff"
100string(30) "              ffffffffffffffff"
101string(10) "0-9A-Fa-f]"
102string(1) "x"
103
104-- Iteration 4 --
105string(16) "ffffffff80000000"
106string(17) "ffffffff80000000x"
107string(16) "ffffffff80000000"
108string(1) "x"
109string(17) " ffffffff80000000"
110string(17) "ffffffff80000000 "
111string(17) "	ffffffff80000000"
112string(17) "
113ffffffff80000000"
114string(16) "ffffffff80000000"
115string(30) "              ffffffff80000000"
116string(10) "0-9A-Fa-f]"
117string(1) "x"
118
119-- Iteration 5 --
120string(16) "ffffffff80000001"
121string(17) "ffffffff80000001x"
122string(16) "ffffffff80000001"
123string(1) "x"
124string(17) " ffffffff80000001"
125string(17) "ffffffff80000001 "
126string(17) "	ffffffff80000001"
127string(17) "
128ffffffff80000001"
129string(16) "ffffffff80000001"
130string(30) "              ffffffff80000001"
131string(10) "0-9A-Fa-f]"
132string(1) "x"
133
134-- Iteration 6 --
135string(8) "7fffffff"
136string(9) "7fffffffx"
137string(8) "7fffffff"
138string(1) "x"
139string(9) " 7fffffff"
140string(9) "7fffffff "
141string(9) "	7fffffff"
142string(9) "
1437fffffff"
144string(8) "7fffffff"
145string(30) "                      7fffffff"
146string(10) "0-9A-Fa-f]"
147string(1) "x"
148
149-- Iteration 7 --
150string(8) "7ffffff8"
151string(9) "7ffffff8x"
152string(8) "7ffffff8"
153string(1) "x"
154string(9) " 7ffffff8"
155string(9) "7ffffff8 "
156string(9) "	7ffffff8"
157string(9) "
1587ffffff8"
159string(8) "7ffffff8"
160string(30) "                      7ffffff8"
161string(10) "0-9A-Fa-f]"
162string(1) "x"
163
164-- Iteration 8 --
165string(4) "123b"
166string(5) "123bx"
167string(4) "123b"
168string(1) "x"
169string(5) " 123b"
170string(5) "123b "
171string(5) "	123b"
172string(5) "
173123b"
174string(4) "123b"
175string(30) "                          123b"
176string(10) "0-9A-Fa-f]"
177string(1) "x"
178
179-- Iteration 9 --
180string(4) "12ab"
181string(5) "12abx"
182string(4) "12ab"
183string(1) "x"
184string(5) " 12ab"
185string(5) "12ab "
186string(5) "	12ab"
187string(5) "
18812ab"
189string(4) "12ab"
190string(30) "                          12ab"
191string(10) "0-9A-Fa-f]"
192string(1) "x"
193
194-- Iteration 10 --
195string(3) "fff"
196string(4) "fffx"
197string(3) "fff"
198string(1) "x"
199string(4) " fff"
200string(4) "fff "
201string(4) "	fff"
202string(4) "
203fff"
204string(4) " fff"
205string(30) "                           fff"
206string(10) "0-9A-Fa-f]"
207string(1) "x"
208
209-- Iteration 11 --
210string(2) "fa"
211string(3) "fax"
212string(2) "fa"
213string(1) "x"
214string(3) " fa"
215string(3) "fa "
216string(3) "	fa"
217string(3) "
218fa"
219string(4) "  fa"
220string(30) "                            fa"
221string(10) "0-9A-Fa-f]"
222string(1) "x"
223
224-- Iteration 12 --
225string(16) "ffffffff80000000"
226string(17) "ffffffff80000000x"
227string(16) "ffffffff80000000"
228string(1) "x"
229string(17) " ffffffff80000000"
230string(17) "ffffffff80000000 "
231string(17) "	ffffffff80000000"
232string(17) "
233ffffffff80000000"
234string(16) "ffffffff80000000"
235string(30) "              ffffffff80000000"
236string(10) "0-9A-Fa-f]"
237string(1) "x"
238
239-- Iteration 13 --
240string(8) "7fffffff"
241string(9) "7fffffffx"
242string(8) "7fffffff"
243string(1) "x"
244string(9) " 7fffffff"
245string(9) "7fffffff "
246string(9) "	7fffffff"
247string(9) "
2487fffffff"
249string(8) "7fffffff"
250string(30) "                      7fffffff"
251string(10) "0-9A-Fa-f]"
252string(1) "x"
253
254-- Iteration 14 --
255string(8) "7fffffff"
256string(9) "7fffffffx"
257string(8) "7fffffff"
258string(1) "x"
259string(9) " 7fffffff"
260string(9) "7fffffff "
261string(9) "	7fffffff"
262string(9) "
2637fffffff"
264string(8) "7fffffff"
265string(30) "                      7fffffff"
266string(10) "0-9A-Fa-f]"
267string(1) "x"
268
269-- Iteration 15 --
270string(2) "53"
271string(3) "53x"
272string(2) "53"
273string(1) "x"
274string(3) " 53"
275string(3) "53 "
276string(3) "	53"
277string(3) "
27853"
279string(4) "  53"
280string(30) "                            53"
281string(10) "0-9A-Fa-f]"
282string(1) "x"
283
284-- Iteration 16 --
285string(1) "1"
286string(2) "1x"
287string(1) "1"
288string(1) "x"
289string(2) " 1"
290string(2) "1 "
291string(2) "	1"
292string(2) "
2931"
294string(4) "   1"
295string(30) "                             1"
296string(10) "0-9A-Fa-f]"
297string(1) "x"
298
299-- Iteration 17 --
300string(16) "ffffffff80000000"
301string(17) "ffffffff80000000x"
302string(16) "ffffffff80000000"
303string(1) "x"
304string(17) " ffffffff80000000"
305string(17) "ffffffff80000000 "
306string(17) "	ffffffff80000000"
307string(17) "
308ffffffff80000000"
309string(16) "ffffffff80000000"
310string(30) "              ffffffff80000000"
311string(10) "0-9A-Fa-f]"
312string(1) "x"
313
314-- Iteration 18 --
315string(8) "7fffffff"
316string(9) "7fffffffx"
317string(8) "7fffffff"
318string(1) "x"
319string(9) " 7fffffff"
320string(9) "7fffffff "
321string(9) "	7fffffff"
322string(9) "
3237fffffff"
324string(8) "7fffffff"
325string(30) "                      7fffffff"
326string(10) "0-9A-Fa-f]"
327string(1) "x"
328Done
329