1--TEST--
2Test vprintf() function : usage variations - char formats with non-char values
3--FILE--
4<?php
5/* Prototype  : string vprintf(string format, array args)
6 * Description: Output a formatted string
7 * Source code: ext/standard/formatted_print.c
8*/
9
10/*
11 * Test vprintf() when different char formats and non-char values are passed to
12 * the '$format' and '$args' arguments of the function
13*/
14
15echo "*** Testing vprintf() : char formats and non-char values ***\n";
16
17// defining an array of various char formats
18$formats =
19  '%c %+c %-c
20   %lc %4c %-4c
21   %10.4c %-10.4c %04c %04.4c
22   %\'10c %\'10c %\'$10c %\'_10c
23   %3$c %4$c %1$c %2$c';
24
25// Arrays of non char values for the format defined in $format.
26// Each sub array contains non char values which correspond to each format in $format
27$args_array = array(
28
29  // array of float values
30  array(65.8, -65.8, +66.8,
31        93.2, 126.8, -126.49,
32        35.44, -35.68, 32.99, -32.00,
33        -61.51, 61.51, 50.49, -54.50,
34        83.33, +84.44, 81.11, 82.22),
35
36  // array of int values
37  array(65, -65, +66,
38        169, 126, -126,
39        35, -35, 32, -32,
40        -61, 61, 50, -54,
41        83, +84, 81, 82),
42
43  // array of strings
44  array(" ", ' ', 'hello',
45        '123hello', '-123hello', '+123hello',
46        "\12345678hello", "-\12345678hello", '0123456hello', 'h123456ello',
47        "1234hello", "hello\0world", "NULL", "true",
48        "3", "4", '1', '2'),
49
50  // different arrays
51  array( array(0), array(1, 2), array(-1, -1),
52         array("123"), array('-123'), array("-123"),
53         array(true), array(false), array(TRUE), array(FALSE),
54         array("123hello"), array("1", "2"), array('123hello'), array(12=>"12twelve"),
55         array("3"), array("4"), array("1"), array("2") ),
56
57  // array of boolean data
58  array( true, TRUE, false,
59         TRUE, FALSE, 1,
60         true, false, TRUE, FALSE,
61         0, 1, 1, 0,
62         1, TRUE, 0, FALSE),
63
64);
65
66// looping to test vprintf() with different char formats from the above $format array
67// and with non-char values from the above $args_array array
68$counter = 1;
69foreach($args_array as $args) {
70  echo "\n-- Iteration $counter --\n";
71  $result = vprintf($formats, $args);
72  echo "\n";
73  var_dump($result);
74  $counter++;
75}
76
77?>
78--EXPECT--
79*** Testing vprintf() : char formats and non-char values ***
80
81-- Iteration 1 --
82A � B
83   ] ~ �
84   # �   �
85   � = 2 �
86   B ] A �
87int(47)
88
89-- Iteration 2 --
90A � B
91   � ~ �
92   # �   �
93   � = 2 �
94   B � A �
95int(47)
96
97-- Iteration 3 --
98� � �
99   { � {
100   � � @ �
101   � � � �
102   � { � �
103int(47)
104
105-- Iteration 4 --
106  
107     
108      
109      
110      
111int(47)
112
113-- Iteration 5 --
114  �
115    � 
116    �  �
117   �   �
118   �   
119int(47)
120