1--TEST--
2Test vprintf() function : usage variations - string formats with non-string values
3--FILE--
4<?php
5/*
6 * Test vprintf() when different string formats and non-string values are passed to
7 * the '$format' and '$args' arguments of the function
8*/
9
10echo "*** Testing vprintf() : string formats and non-string values ***\n";
11
12// defining array of string formats
13$formats =
14    '%s %+s %-s
15    %ls %4s %-4s
16    %10.4s %-10.4s %04s %04.4s
17    %\'#2s %\'2s %\'$2s %\'_2s
18    %3$s %4$s %1$s %2$s';
19
20// Arrays of non string values for the format defined in $format.
21// Each sub array contains non string values which correspond to each format in $format
22$args_array = array(
23
24  // array of float values
25  array(2.2, .2, 10.2,
26        123456.234, -1234.6789, +1234.6789,
27        2.1234567e10, +2.7654321e10, -2.7654321e10,
28        12345.780, 12.000000011111, -12.00000111111, -123456.234,
29        3.33, +4.44, 1.11,-2.22 ),
30
31 // array of int values
32 array(2, -2, +2,
33       123456, -12346789, +12346789,
34       123200, +20000, -40000, 22212,
35       12345780, 1211111, -12111111, -12345634,
36       3, +4, 1,-2 ),
37
38
39  // different arrays
40  array( array(0), array(1, 2), array(-1, -1),
41         array("123"), array('-123'), array("-123"),
42         array(true), array(false), array(TRUE), array(FALSE),
43         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
44         array("3"), array("4"), array("1"), array("2") ),
45
46  // array of boolean data
47  array( true, TRUE, false,
48         TRUE, FALSE, 1,
49         true, false, TRUE, FALSE,
50         0, 1, 1, 0,
51         1, TRUE, 0, FALSE),
52
53);
54
55// looping to test vprintf() with different string formats from the above $format array
56// and with non-string values from the above $args_array array
57$counter = 1;
58foreach($args_array as $args) {
59  echo "\n-- Iteration $counter --\n";
60  $result = vprintf($formats, $args);
61  echo "\n";
62  var_dump($result);
63  $counter++;
64}
65
66?>
67--EXPECTF--
68*** Testing vprintf() : string formats and non-string values ***
69
70-- Iteration 1 --
712.2 0.2 10.2
72    123456.234 -1234.6789 1234.6789
73          2123 2765       -27654321000 1234
74    12.000000011111 -12.00000111111 -123456.234 3.33
75    10.2 123456.234 2.2 0.2
76int(173)
77
78-- Iteration 2 --
792 -2 2
80    123456 -12346789 12346789
81          1232 2000       -40000 2221
82    12345780 1211111 -12111111 -12345634
83    2 123456 2 -2
84int(133)
85
86-- Iteration 3 --
87
88Warning: Array to string conversion in %s on line %d
89
90Warning: Array to string conversion in %s on line %d
91
92Warning: Array to string conversion in %s on line %d
93
94Warning: Array to string conversion in %s on line %d
95
96Warning: Array to string conversion in %s on line %d
97
98Warning: Array to string conversion in %s on line %d
99
100Warning: Array to string conversion in %s on line %d
101
102Warning: Array to string conversion in %s on line %d
103
104Warning: Array to string conversion in %s on line %d
105
106Warning: Array to string conversion in %s on line %d
107
108Warning: Array to string conversion in %s on line %d
109
110Warning: Array to string conversion in %s on line %d
111
112Warning: Array to string conversion in %s on line %d
113
114Warning: Array to string conversion in %s on line %d
115
116Warning: Array to string conversion in %s on line %d
117
118Warning: Array to string conversion in %s on line %d
119
120Warning: Array to string conversion in %s on line %d
121
122Warning: Array to string conversion in %s on line %d
123Array Array Array
124    Array Array Array
125          Arra Arra       Array Arra
126    Array Array Array Array
127    Array Array Array Array
128int(132)
129
130-- Iteration 4 --
1311 1
132    1      1
133             1            0001 0000
134    #0 1 $1 _0
135     1 1 1
136int(82)
137