1--TEST--
2Test vprintf() function : usage variations - int formats with non-integer 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/*
10 * Test vprintf() when different int formats and non-int values are passed to
11 * the '$format' and '$args' arguments of the function
12*/
13
14echo "*** Testing vprintf() : int formats and non-integer values ***\n";
15
16// defining array of int formats
17$formats =
18    '%d %+d %-d
19    %ld %4d %-4d
20    %10.4d %-10.4d %.4d %04.4d
21    %\'#2d %\'2d %\'$2d %\'_2d
22    %3$d %4$d %1$d %2$d';
23
24// Arrays of non int values for the format defined in $format.
25// Each sub array contains non int values which correspond to each format in $format
26$args_array = array(
27
28  // array of float values
29  array(2.2, .2, 10.2,
30        123456.234, -1234.6789, +1234.6789,
31        2e10, +2e5, 4e3, 22e+6,
32        12345.780, 12.000000011111, -12.00000111111, -123456.234,
33        3.33, +4.44, 1.11,-2.22 ),
34
35  // array of strings
36  array(" ", ' ', 'hello',
37        '123hello', '-123hello', '+123hello',
38        "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
39        "1234hello", "hello\0world", "NULL", "true",
40        "3", "4", '1', '2'),
41
42  // different arrays
43  array( array(0), array(1, 2), array(-1, -1),
44         array("123"), array('-123'), array("-123"),
45         array(true), array(false), array(TRUE), array(FALSE),
46         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
47         array("3"), array("4"), array("1"), array("2") ),
48
49  // array of boolean data
50  array( true, TRUE, false,
51         TRUE, FALSE, 1,
52         true, false, TRUE, FALSE,
53         0, 1, 1, 0,
54         1, TRUE, 0, FALSE),
55
56);
57
58// looping to test vprintf() with different int formats from the above $format array
59// and with non-int values from the above $args_array array
60$counter = 1;
61foreach($args_array as $args) {
62  echo "\n-- Iteration $counter --\n";
63  $result = vprintf($formats, $args);
64  echo "\n";
65  var_dump($result);
66  $counter++;
67}
68
69?>
70--EXPECT--
71*** Testing vprintf() : int formats and non-integer values ***
72
73-- Iteration 1 --
742 +0 10
75    123456 -1234 1234
76    20000000000 200000     4000 22000000
77    12345 12 -12 -123456
78    10 123456 2 0
79int(113)
80
81-- Iteration 2 --
820 +0 0
83    123 -123 123
84             0 0          123456 0000
85    1234 0 $0 _0
86    0 123 0 0
87int(93)
88
89-- Iteration 3 --
901 +1 1
91    1    1 1
92             1 1          1 0001
93    #1 1 $1 _1
94    1 1 1 1
95int(82)
96
97-- Iteration 4 --
981 +1 0
99    1    0 1
100             1 0          1 0000
101    #0 1 $1 _0
102    0 1 1 1
103int(82)
104