1--TEST--
2Test vsprintf() function : usage variations - float formats with non-float values
3--FILE--
4<?php
5/* Prototype  : string vsprintf(string format, array args)
6 * Description: Return a formatted string
7 * Source code: ext/standard/formatted_print.c
8*/
9
10/*
11 * Test vsprintf() when different float formats and non-float values are passed to
12 * the '$format' and '$args' arguments of the function
13*/
14
15echo "*** Testing vsprintf() : float formats and non-float values ***\n";
16
17// defining array of float formats
18$formats =
19  '%f %+f %-f
20   %lf %Lf %4f %-4f
21   %10.4f %-10.4f %04f %04.4f
22   %\'#2f %\'2f %\'$2f %\'_2f
23   %3$f %4$f %1$f %2$f';
24
25// Arrays of non float values for the format defined in $format.
26// Each sub array contains non float values which correspond to each format in $format
27$args_array = array(
28
29  // array of int values
30  array(2, -2, +2,
31        123456, 123456234, -12346789, +12346789,
32        123200, +20000, -40000, 22212,
33        12345780, 1211111, -12111111, -12345634,
34        3, +4, 1,-2 ),
35
36  // array of strings
37  array(" ", ' ', 'hello',
38        '123hello', "123hello", '-123hello', '+123hello',
39        "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
40        "1234hello", "hello\0world", "NULL", "true",
41        "3", "4", '1', '2'),
42
43  // different arrays
44  array( array(0), array(1, 2), array(-1, -1),
45         array("123"), array('123'), array('-123'), array("-123"),
46         array(true), array(false), array(TRUE), array(FALSE),
47         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
48         array("3"), array("4"), array("1"), array("2") ),
49
50  // array of boolean data
51  array( true, TRUE, false,
52         TRUE, 0, FALSE, 1,
53         true, false, TRUE, FALSE,
54         0, 1, 1, 0,
55         1, TRUE, 0, FALSE),
56
57);
58
59// looping to test vsprintf() with different float formats from the above $format array
60// and with non-float values from the above $args_array array
61$counter = 1;
62foreach($args_array as $args) {
63  echo "\n-- Iteration $counter --\n";
64  var_dump( vsprintf($formats, $args) );
65  $counter++;
66}
67
68echo "Done";
69?>
70--EXPECTF--
71*** Testing vsprintf() : float formats and non-float values ***
72
73-- Iteration 1 --
74string(244) "2.000000 -2.000000 2.000000
75   123456.000000 f -12346789.000000 12346789.000000
76   123200.0000 20000.0000 -40000.000000 22212.0000
77   12345780.000000 1211111.000000 -12111111.000000 -12345634.000000
78   2.000000 123456.000000 2.000000 -2.000000"
79
80-- Iteration 2 --
81string(196) "0.000000 +0.000000 0.000000
82   123.000000 f -123.000000 123.000000
83       0.0000 0.0000     123456.000000 0.0000
84   1234.000000 0.000000 0.000000 0.000000
85   0.000000 123.000000 0.000000 0.000000"
86
87-- Iteration 3 --
88string(179) "1.000000 +1.000000 1.000000
89   1.000000 f 1.000000 1.000000
90       1.0000 1.0000     1.000000 1.0000
91   1.000000 1.000000 1.000000 1.000000
92   1.000000 1.000000 1.000000 1.000000"
93
94-- Iteration 4 --
95string(179) "1.000000 +1.000000 0.000000
96   1.000000 f 0.000000 1.000000
97       1.0000 0.0000     1.000000 0.0000
98   0.000000 1.000000 1.000000 0.000000
99   0.000000 1.000000 1.000000 1.000000"
100Done
101