1--TEST--
2Test printf() function : usage variations - with all types of values for arg1 argument
3--FILE--
4<?php
5echo "*** Testing printf() : with different types of values passed for arg1 argument ***\n";
6
7// initialing required variables
8$format = '%s';
9$arg2 = 'third argument';
10
11//get an unset variable
12$unset_var = 10;
13unset ($unset_var);
14
15// declaring class
16class sample
17{
18  public function __toString() {
19    return "Object";
20  }
21}
22
23// creating a file resource
24$file_handle = fopen(__FILE__, 'r');
25
26//array of values to iterate over
27$values = array(
28
29          // int data
30/*1*/     0,
31          1,
32          12345,
33          -2345,
34
35          // float data
36/*5*/     10.5,
37          -10.5,
38          10.1234567e10,
39          10.7654321E-10,
40          .5,
41
42          // array data
43/*10*/    array(),
44          array(0),
45          array(1),
46          array(1, 2),
47          array('color' => 'red', 'item' => 'pen'),
48
49          // null data
50/*15*/    NULL,
51          null,
52
53          // boolean data
54/*17*/    true,
55          false,
56          TRUE,
57          FALSE,
58
59          // empty data
60/*21*/    "",
61          '',
62
63          // string data
64/*23*/    "string",
65          'string',
66
67          // object data
68/*25*/    new sample(),
69
70          // undefined data
71/*26*/    @$undefined_var,
72
73          // unset data
74/*27*/    @$unset_var,
75
76          // resource data
77/*28*/    $file_handle
78);
79
80// loop through each element of the array for arg1
81
82$count = 1;
83foreach($values as $value) {
84  echo "\n-- Iteration $count --\n";
85
86  // with two arguments
87  $result = printf($format, $value);
88  echo "\n";
89  var_dump($result);
90
91  // with three arguments
92  $result = printf($format, $value, $arg2);
93  echo "\n";
94  var_dump($result);
95
96  $count++;
97};
98
99// closing the resource
100fclose($file_handle);
101
102?>
103--EXPECTF--
104*** Testing printf() : with different types of values passed for arg1 argument ***
105
106-- Iteration 1 --
1070
108int(1)
1090
110int(1)
111
112-- Iteration 2 --
1131
114int(1)
1151
116int(1)
117
118-- Iteration 3 --
11912345
120int(5)
12112345
122int(5)
123
124-- Iteration 4 --
125-2345
126int(5)
127-2345
128int(5)
129
130-- Iteration 5 --
13110.5
132int(4)
13310.5
134int(4)
135
136-- Iteration 6 --
137-10.5
138int(5)
139-10.5
140int(5)
141
142-- Iteration 7 --
143101234567000
144int(12)
145101234567000
146int(12)
147
148-- Iteration 8 --
1491.07654321E-9
150int(13)
1511.07654321E-9
152int(13)
153
154-- Iteration 9 --
1550.5
156int(3)
1570.5
158int(3)
159
160-- Iteration 10 --
161
162Warning: Array to string conversion in %s on line %d
163Array
164int(5)
165
166Warning: Array to string conversion in %s on line %d
167Array
168int(5)
169
170-- Iteration 11 --
171
172Warning: Array to string conversion in %s on line %d
173Array
174int(5)
175
176Warning: Array to string conversion in %s on line %d
177Array
178int(5)
179
180-- Iteration 12 --
181
182Warning: Array to string conversion in %s on line %d
183Array
184int(5)
185
186Warning: Array to string conversion in %s on line %d
187Array
188int(5)
189
190-- Iteration 13 --
191
192Warning: Array to string conversion in %s on line %d
193Array
194int(5)
195
196Warning: Array to string conversion in %s on line %d
197Array
198int(5)
199
200-- Iteration 14 --
201
202Warning: Array to string conversion in %s on line %d
203Array
204int(5)
205
206Warning: Array to string conversion in %s on line %d
207Array
208int(5)
209
210-- Iteration 15 --
211
212int(0)
213
214int(0)
215
216-- Iteration 16 --
217
218int(0)
219
220int(0)
221
222-- Iteration 17 --
2231
224int(1)
2251
226int(1)
227
228-- Iteration 18 --
229
230int(0)
231
232int(0)
233
234-- Iteration 19 --
2351
236int(1)
2371
238int(1)
239
240-- Iteration 20 --
241
242int(0)
243
244int(0)
245
246-- Iteration 21 --
247
248int(0)
249
250int(0)
251
252-- Iteration 22 --
253
254int(0)
255
256int(0)
257
258-- Iteration 23 --
259string
260int(6)
261string
262int(6)
263
264-- Iteration 24 --
265string
266int(6)
267string
268int(6)
269
270-- Iteration 25 --
271Object
272int(6)
273Object
274int(6)
275
276-- Iteration 26 --
277
278int(0)
279
280int(0)
281
282-- Iteration 27 --
283
284int(0)
285
286int(0)
287
288-- Iteration 28 --
289Resource id #%d
290int(%d)
291Resource id #%d
292int(%d)
293