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 %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, -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, -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', '+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'), 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, 0, 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===DONE===
79--EXPECT--
80*** Testing vprintf() : char formats and non-char values ***
81
82-- Iteration 1 --
83A � B
84   ] c ~ �
85   # �   �
86   � = 2 �
87   B ] A �
88int(50)
89
90-- Iteration 2 --
91A � B
92   � c ~ �
93   # �   �
94   � = 2 �
95   B � A �
96int(50)
97
98-- Iteration 3 --
99� � �
100   { c � {
101   � � @ �
102   � � � �
103   � { � �
104int(50)
105
106-- Iteration 4 --
107  
108    c  
109      
110      
111      
112int(50)
113
114-- Iteration 5 --
115  �
116    c � 
117    �  �
118   �   �
119   �   
120int(50)
121===DONE===
122