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
7echo "*** Testing sprintf() : hexa 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 hexa formats
32$hexa_formats = array(
33  "%x", "%xx", "%lx", " %x", "%x ",
34  "\t%x", "\n%x", "%4x", "%30x",
35);
36
37$count = 1;
38foreach($integer_values as $integer_value) {
39  echo "\n-- Iteration $count --\n";
40
41  foreach($hexa_formats as $format) {
42    var_dump( sprintf($format, $integer_value) );
43  }
44  $count++;
45};
46
47echo "Done";
48?>
49--EXPECT--
50*** Testing sprintf() : hexa formats with integer values ***
51
52-- Iteration 1 --
53string(1) "0"
54string(2) "0x"
55string(1) "0"
56string(2) " 0"
57string(2) "0 "
58string(2) "	0"
59string(2) "
600"
61string(4) "   0"
62string(30) "                             0"
63
64-- Iteration 2 --
65string(1) "1"
66string(2) "1x"
67string(1) "1"
68string(2) " 1"
69string(2) "1 "
70string(2) "	1"
71string(2) "
721"
73string(4) "   1"
74string(30) "                             1"
75
76-- Iteration 3 --
77string(16) "ffffffffffffffff"
78string(17) "ffffffffffffffffx"
79string(16) "ffffffffffffffff"
80string(17) " ffffffffffffffff"
81string(17) "ffffffffffffffff "
82string(17) "	ffffffffffffffff"
83string(17) "
84ffffffffffffffff"
85string(16) "ffffffffffffffff"
86string(30) "              ffffffffffffffff"
87
88-- Iteration 4 --
89string(16) "ffffffff80000000"
90string(17) "ffffffff80000000x"
91string(16) "ffffffff80000000"
92string(17) " ffffffff80000000"
93string(17) "ffffffff80000000 "
94string(17) "	ffffffff80000000"
95string(17) "
96ffffffff80000000"
97string(16) "ffffffff80000000"
98string(30) "              ffffffff80000000"
99
100-- Iteration 5 --
101string(16) "ffffffff80000001"
102string(17) "ffffffff80000001x"
103string(16) "ffffffff80000001"
104string(17) " ffffffff80000001"
105string(17) "ffffffff80000001 "
106string(17) "	ffffffff80000001"
107string(17) "
108ffffffff80000001"
109string(16) "ffffffff80000001"
110string(30) "              ffffffff80000001"
111
112-- Iteration 6 --
113string(8) "7fffffff"
114string(9) "7fffffffx"
115string(8) "7fffffff"
116string(9) " 7fffffff"
117string(9) "7fffffff "
118string(9) "	7fffffff"
119string(9) "
1207fffffff"
121string(8) "7fffffff"
122string(30) "                      7fffffff"
123
124-- Iteration 7 --
125string(8) "7ffffff8"
126string(9) "7ffffff8x"
127string(8) "7ffffff8"
128string(9) " 7ffffff8"
129string(9) "7ffffff8 "
130string(9) "	7ffffff8"
131string(9) "
1327ffffff8"
133string(8) "7ffffff8"
134string(30) "                      7ffffff8"
135
136-- Iteration 8 --
137string(4) "123b"
138string(5) "123bx"
139string(4) "123b"
140string(5) " 123b"
141string(5) "123b "
142string(5) "	123b"
143string(5) "
144123b"
145string(4) "123b"
146string(30) "                          123b"
147
148-- Iteration 9 --
149string(4) "12ab"
150string(5) "12abx"
151string(4) "12ab"
152string(5) " 12ab"
153string(5) "12ab "
154string(5) "	12ab"
155string(5) "
15612ab"
157string(4) "12ab"
158string(30) "                          12ab"
159
160-- Iteration 10 --
161string(3) "fff"
162string(4) "fffx"
163string(3) "fff"
164string(4) " fff"
165string(4) "fff "
166string(4) "	fff"
167string(4) "
168fff"
169string(4) " fff"
170string(30) "                           fff"
171
172-- Iteration 11 --
173string(2) "fa"
174string(3) "fax"
175string(2) "fa"
176string(3) " fa"
177string(3) "fa "
178string(3) "	fa"
179string(3) "
180fa"
181string(4) "  fa"
182string(30) "                            fa"
183
184-- Iteration 12 --
185string(16) "ffffffff80000000"
186string(17) "ffffffff80000000x"
187string(16) "ffffffff80000000"
188string(17) " ffffffff80000000"
189string(17) "ffffffff80000000 "
190string(17) "	ffffffff80000000"
191string(17) "
192ffffffff80000000"
193string(16) "ffffffff80000000"
194string(30) "              ffffffff80000000"
195
196-- Iteration 13 --
197string(8) "7fffffff"
198string(9) "7fffffffx"
199string(8) "7fffffff"
200string(9) " 7fffffff"
201string(9) "7fffffff "
202string(9) "	7fffffff"
203string(9) "
2047fffffff"
205string(8) "7fffffff"
206string(30) "                      7fffffff"
207
208-- Iteration 14 --
209string(8) "7fffffff"
210string(9) "7fffffffx"
211string(8) "7fffffff"
212string(9) " 7fffffff"
213string(9) "7fffffff "
214string(9) "	7fffffff"
215string(9) "
2167fffffff"
217string(8) "7fffffff"
218string(30) "                      7fffffff"
219
220-- Iteration 15 --
221string(2) "53"
222string(3) "53x"
223string(2) "53"
224string(3) " 53"
225string(3) "53 "
226string(3) "	53"
227string(3) "
22853"
229string(4) "  53"
230string(30) "                            53"
231
232-- Iteration 16 --
233string(1) "1"
234string(2) "1x"
235string(1) "1"
236string(2) " 1"
237string(2) "1 "
238string(2) "	1"
239string(2) "
2401"
241string(4) "   1"
242string(30) "                             1"
243
244-- Iteration 17 --
245string(16) "ffffffff80000000"
246string(17) "ffffffff80000000x"
247string(16) "ffffffff80000000"
248string(17) " ffffffff80000000"
249string(17) "ffffffff80000000 "
250string(17) "	ffffffff80000000"
251string(17) "
252ffffffff80000000"
253string(16) "ffffffff80000000"
254string(30) "              ffffffff80000000"
255
256-- Iteration 18 --
257string(8) "7fffffff"
258string(9) "7fffffffx"
259string(8) "7fffffff"
260string(9) " 7fffffff"
261string(9) "7fffffff "
262string(9) "	7fffffff"
263string(9) "
2647fffffff"
265string(8) "7fffffff"
266string(30) "                      7fffffff"
267Done
268