1--TEST--
2Test vprintf() function : usage variations - string formats with non-string values
3--FILE--
4<?php
5/* Prototype  : string vprintf(string format, array args)
6 * Description: Return a formatted string
7 * Source code: ext/standard/formatted_print.c
8*/
9
10/*
11 * Test vprintf() when different string formats and non-string values are passed to
12 * the '$format' and '$args' arguments of the function
13*/
14
15error_reporting(E_ALL & ~E_NOTICE);
16
17echo "*** Testing vprintf() : string formats and non-string values ***\n";
18
19// defining array of string formats
20$formats =
21  '%s %+s %-s
22   %ls %Ls %4s %-4s
23   %10.4s %-10.4s %04s %04.4s
24   %\'#2s %\'2s %\'$2s %\'_2s
25   %3$s %4$s %1$s %2$s';
26
27// Arrays of non string values for the format defined in $format.
28// Each sub array contains non string values which correspond to each format in $format
29$args_array = array(
30
31  // array of float values
32  array(2.2, .2, 10.2,
33        123456.234, 123456.234, -1234.6789, +1234.6789,
34        2.1234567e10, +2.7654321e10, -2.7654321e10,
35        12345.780, 12.000000011111, -12.00000111111, -123456.234,
36        3.33, +4.44, 1.11,-2.22 ),
37
38 // array of int values
39 array(2, -2, +2,
40       123456, 123456234, -12346789, +12346789,
41       123200, +20000, -40000, 22212,
42       12345780, 1211111, -12111111, -12345634,
43       3, +4, 1,-2 ),
44
45
46  // different arrays
47  array( array(0), array(1, 2), array(-1, -1),
48         array("123"), array('123'), array('-123'), array("-123"),
49         array(true), array(false), array(TRUE), array(FALSE),
50         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
51         array("3"), array("4"), array("1"), array("2") ),
52
53  // array of boolean data
54  array( true, TRUE, false,
55         TRUE, 0, FALSE, 1,
56         true, false, TRUE, FALSE,
57         0, 1, 1, 0,
58         1, TRUE, 0, FALSE),
59
60);
61
62// looping to test vprintf() with different string formats from the above $format array
63// and with non-string values from the above $args_array array
64$counter = 1;
65foreach($args_array as $args) {
66  echo "\n-- Iteration $counter --\n";
67  $result = vprintf($formats, $args);
68  echo "\n";
69  var_dump($result);
70  $counter++;
71}
72
73?>
74===DONE===
75--EXPECT--
76*** Testing vprintf() : string formats and non-string values ***
77
78-- Iteration 1 --
792.2 0.2 10.2
80   123456.234 s -1234.6789 1234.6789
81         2123 2765       -27654321000 1234
82   12.000000011111 -12.00000111111 -123456.234 3.33
83   10.2 123456.234 2.2 0.2
84int(172)
85
86-- Iteration 2 --
872 -2 2
88   123456 s -12346789 12346789
89         1232 2000       -40000 2221
90   12345780 1211111 -12111111 -12345634
91   2 123456 2 -2
92int(132)
93
94-- Iteration 3 --
95Array Array Array
96   Array s Array Array
97         Arra Arra       Array Arra
98   Array Array Array Array
99   Array Array Array Array
100int(131)
101
102-- Iteration 4 --
1031 1
104   1 s      1
105            1            0001 0000
106   #0 1 $1 _0
107    1 1 1
108int(81)
109===DONE===
110