1--TEST--
2Test vsprintf() function : usage variations - unexpected values for the format argument
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 unexpected format strings are passed to
12 * the '$format' argument of the function
13*/
14
15echo "*** Testing vsprintf() : with unexpected values for format argument ***\n";
16
17// initialising the required variables
18$args = array(1, 2);
19
20//get an unset variable
21$unset_var = 10;
22unset ($unset_var);
23
24// declaring a class
25class sample
26{
27  public function __toString() {
28  return "object";
29  }
30}
31
32// Defining resource
33$file_handle = fopen(__FILE__, 'r');
34
35
36//array of values to iterate over
37$values = array(
38
39  // int data
40  0,
41  1,
42  12345,
43  -2345,
44
45  // float data
46  10.5,
47  -10.5,
48  10.1234567e10,
49  10.7654321E-10,
50  .5,
51
52  // array data
53  array(),
54  array(0),
55  array(1),
56  array(1,2),
57  array('color' => 'red', 'item' => 'pen'),
58
59  // null data
60  NULL,
61  null,
62
63  // boolean data
64  true,
65  false,
66  TRUE,
67  FALSE,
68
69  // empty data
70  "",
71  '',
72
73  // object data
74  new sample(),
75
76  // undefined data
77  @$undefined_var,
78
79  // unset data
80  @$unset_var,
81
82  // resource data
83  $file_handle
84);
85
86// loop through each element of the array for format
87
88$counter = 1;
89foreach($values as $value) {
90  echo "\n -- Iteration $counter --\n";
91  var_dump( vsprintf($value,$args) );
92  $counter++;
93
94};
95
96// closing the resource
97fclose($file_handle);
98
99echo "Done";
100?>
101--EXPECTF--
102*** Testing vsprintf() : with unexpected values for format argument ***
103
104 -- Iteration 1 --
105string(1) "0"
106
107 -- Iteration 2 --
108string(1) "1"
109
110 -- Iteration 3 --
111string(5) "12345"
112
113 -- Iteration 4 --
114string(5) "-2345"
115
116 -- Iteration 5 --
117string(4) "10.5"
118
119 -- Iteration 6 --
120string(5) "-10.5"
121
122 -- Iteration 7 --
123string(12) "101234567000"
124
125 -- Iteration 8 --
126string(13) "1.07654321E-9"
127
128 -- Iteration 9 --
129string(3) "0.5"
130
131 -- Iteration 10 --
132
133Notice: Array to string conversion in %s on line %d
134string(5) "Array"
135
136 -- Iteration 11 --
137
138Notice: Array to string conversion in %s on line %d
139string(5) "Array"
140
141 -- Iteration 12 --
142
143Notice: Array to string conversion in %s on line %d
144string(5) "Array"
145
146 -- Iteration 13 --
147
148Notice: Array to string conversion in %s on line %d
149string(5) "Array"
150
151 -- Iteration 14 --
152
153Notice: Array to string conversion in %s on line %d
154string(5) "Array"
155
156 -- Iteration 15 --
157string(0) ""
158
159 -- Iteration 16 --
160string(0) ""
161
162 -- Iteration 17 --
163string(1) "1"
164
165 -- Iteration 18 --
166string(0) ""
167
168 -- Iteration 19 --
169string(1) "1"
170
171 -- Iteration 20 --
172string(0) ""
173
174 -- Iteration 21 --
175string(0) ""
176
177 -- Iteration 22 --
178string(0) ""
179
180 -- Iteration 23 --
181string(6) "object"
182
183 -- Iteration 24 --
184string(0) ""
185
186 -- Iteration 25 --
187string(0) ""
188
189 -- Iteration 26 --
190string(%d) "Resource id #%d"
191Done
192