1--TEST--
2Test vprintf() function : usage variations - unexpected values for the format argument
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 unexpected format strings are passed to
12 * the '$format' argument of the function
13*/
14
15echo "*** Testing vprintf() : 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/*1*/	  0,
41		  1,
42		  12345,
43		  -2345,
44
45		  // float data
46/*5*/	  10.5,
47		  -10.5,
48		  10.1234567e10,
49		  10.7654321E-10,
50		  .5,
51
52		  // array data
53/*10*/	  array(),
54		  array(0),
55		  array(1),
56		  array(1,2),
57		  array('color' => 'red', 'item' => 'pen'),
58
59		  // null data
60/*15*/	  NULL,
61		  null,
62
63		  // boolean data
64/*17*/	  true,
65		  false,
66		  TRUE,
67		  FALSE,
68
69		  // empty data
70/*21*/	  "",
71		  '',
72
73		  // object data
74/*23*/	  new sample(),
75
76		  // undefined data
77/*24*/	  @$undefined_var,
78
79		  // unset data
80/*25*/	  @$unset_var,
81
82		  // resource data
83/*26*/	  $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  $result = vprintf($value,$args);
92  echo "\n";
93  var_dump($result);
94  $counter++;
95
96};
97
98// closing the resource
99fclose($file_handle);
100
101?>
102===DONE===
103--EXPECTF--
104*** Testing vprintf() : with unexpected values for format argument ***
105
106 -- Iteration 1 --
1070
108int(1)
109
110 -- Iteration 2 --
1111
112int(1)
113
114 -- Iteration 3 --
11512345
116int(5)
117
118 -- Iteration 4 --
119-2345
120int(5)
121
122 -- Iteration 5 --
12310.5
124int(4)
125
126 -- Iteration 6 --
127-10.5
128int(5)
129
130 -- Iteration 7 --
131101234567000
132int(12)
133
134 -- Iteration 8 --
1351.07654321E-9
136int(13)
137
138 -- Iteration 9 --
1390.5
140int(3)
141
142 -- Iteration 10 --
143
144Notice: Array to string conversion in %s on line %d
145Array
146int(5)
147
148 -- Iteration 11 --
149
150Notice: Array to string conversion in %s on line %d
151Array
152int(5)
153
154 -- Iteration 12 --
155
156Notice: Array to string conversion in %s on line %d
157Array
158int(5)
159
160 -- Iteration 13 --
161
162Notice: Array to string conversion in %s on line %d
163Array
164int(5)
165
166 -- Iteration 14 --
167
168Notice: Array to string conversion in %s on line %d
169Array
170int(5)
171
172 -- Iteration 15 --
173
174int(0)
175
176 -- Iteration 16 --
177
178int(0)
179
180 -- Iteration 17 --
1811
182int(1)
183
184 -- Iteration 18 --
185
186int(0)
187
188 -- Iteration 19 --
1891
190int(1)
191
192 -- Iteration 20 --
193
194int(0)
195
196 -- Iteration 21 --
197
198int(0)
199
200 -- Iteration 22 --
201
202int(0)
203
204 -- Iteration 23 --
205object
206int(6)
207
208 -- Iteration 24 --
209
210int(0)
211
212 -- Iteration 25 --
213
214int(0)
215
216 -- Iteration 26 --
217Resource id #%d
218int(%d)
219===DONE===
220