1--TEST--
2Test vsprintf() function : usage variations - hexa formats with hexa values
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6?>
7--FILE--
8<?php
9/* Prototype  : string vsprintf(string format, array args)
10 * Description: Return a formatted string
11 * Source code: ext/standard/formatted_print.c
12*/
13
14/*
15 * Test vsprintf() when different hexa formats and hexa values are passed to
16 * the '$format' and '$args' arguments of the function
17*/
18
19echo "*** Testing vsprintf() : hexa formats with hexa values ***\n";
20
21// defining array of different hexa formats
22$formats = array(
23  "%x",
24  "%+x %-x %X",
25  "%lx %Lx, %4x %-4x",
26  "%10.4x %-10.4x %04x %04.4x",
27  "%'#2x %'2x %'$2x %'_2x",
28  "%x %x %x %x",
29  "% %%x x%",
30  '%3$x %4$x %1$x %2$x'
31);
32
33// Arrays of hexa values for the format defined in $format.
34// Each sub array contains hexa values which correspond to each format string in $format
35$args_array = array(
36  array(0x0),
37  array(-0x1, 0x1, +0x22),
38  array(0x7FFFFFFF, -0x7fffffff, +0x7000000, -0x80000000),
39  array(123456, 12345678, -1234567, 1234567),
40  array(1, 0x2222, 0333333, -0x44444444),
41  array(0x123b, 0xfAb, "0xaxz", 012),
42  array(0x1234, 0x34, 0x2ff),
43  array(0x3, 0x4, 0x1, 0x2)
44
45);
46
47// looping to test vsprintf() with different char octal from the above $format array
48// and with octal values from the above $args_array array
49$counter = 1;
50foreach($formats as $format) {
51  echo "\n-- Iteration $counter --\n";
52  var_dump( vsprintf($format, $args_array[$counter-1]) );
53  $counter++;
54}
55
56echo "Done";
57?>
58--EXPECT--
59*** Testing vsprintf() : hexa formats with hexa values ***
60
61-- Iteration 1 --
62string(1) "0"
63
64-- Iteration 2 --
65string(21) "ffffffffffffffff 1 22"
66
67-- Iteration 3 --
68string(36) "7fffffff x, 7000000 ffffffff80000000"
69
70-- Iteration 4 --
71string(43) "                      ffffffffffed2979 0000"
72
73-- Iteration 5 --
74string(30) "#1 2222 1b6db ffffffffbbbbbbbc"
75
76-- Iteration 6 --
77string(12) "123b fab 0 a"
78
79-- Iteration 7 --
80string(5) "%34 x"
81
82-- Iteration 8 --
83string(7) "1 2 3 4"
84Done
85