1--TEST--
2Test printf() function : usage variations - unexpected values for format argument
3--FILE--
4<?php
5/* Prototype  : int printf  ( string $format  [, mixed $args  [, mixed $...  ]] )
6 * Description: Produces output according to format .
7 * Source code: ext/standard/formatted_print.c
8 */
9
10/*
11* Testing printf() : with different unexpected values for format argument other than the strings
12*/
13
14echo "*** Testing printf() : with unexpected values for format argument ***\n";
15
16// initialing required variables
17$arg1 = "second arg";
18$arg2 = "third arg";
19
20//get an unset variable
21$unset_var = 10;
22unset ($unset_var);
23
24// declaring class
25class sample
26{
27  public function __toString() {
28    return "Object";
29  }
30}
31
32// creating a file resource
33$file_handle = fopen(__FILE__, 'r');
34
35//array of values to iterate over
36$values = array(
37
38		  // int data
39/*1*/	  0,
40	      1,
41	      12345,
42	      -2345,
43
44	      // float data
45/*5*/      10.5,
46	      -10.5,
47	      10.1234567e10,
48	      10.7654321E-10,
49	      .5,
50
51	      // array data
52/*10*/    array(),
53	      array(0),
54	      array(1),
55	      array(1, 2),
56	      array('color' => 'red', 'item' => 'pen'),
57
58	      // null data
59/*15*/    NULL,
60	      null,
61
62	      // boolean data
63/*17*/    true,
64	      false,
65	      TRUE,
66	      FALSE,
67
68	      // empty data
69/*21*/    "",
70	      '',
71
72	      // object data
73/*23*/    new sample(),
74
75	      // undefined data
76/*24*/    @$undefined_var,
77
78	      // unset data
79/*25*/    @$unset_var,
80
81	      // resource data
82/*26*/    $file_handle
83);
84
85// loop through each element of the array for format
86
87$count = 1;
88foreach($values as $value) {
89  echo "\n-- Iteration $count --\n";
90
91  // with default argument
92  $result = printf($value);
93  echo "\n";
94  var_dump($result);
95
96  // with two arguments
97  $result = printf($value, $arg1);
98  echo "\n";
99  var_dump($result);
100
101  // with three arguments
102  $result = printf($value, $arg1, $arg2);
103  echo "\n";
104  var_dump($result);
105
106  $count++;
107};
108
109// close the resource
110fclose($file_handle);
111
112?>
113===DONE===
114--EXPECTF--
115*** Testing printf() : with unexpected values for format argument ***
116
117-- Iteration 1 --
1180
119int(1)
1200
121int(1)
1220
123int(1)
124
125-- Iteration 2 --
1261
127int(1)
1281
129int(1)
1301
131int(1)
132
133-- Iteration 3 --
13412345
135int(5)
13612345
137int(5)
13812345
139int(5)
140
141-- Iteration 4 --
142-2345
143int(5)
144-2345
145int(5)
146-2345
147int(5)
148
149-- Iteration 5 --
15010.5
151int(4)
15210.5
153int(4)
15410.5
155int(4)
156
157-- Iteration 6 --
158-10.5
159int(5)
160-10.5
161int(5)
162-10.5
163int(5)
164
165-- Iteration 7 --
166101234567000
167int(12)
168101234567000
169int(12)
170101234567000
171int(12)
172
173-- Iteration 8 --
1741.07654321E-9
175int(13)
1761.07654321E-9
177int(13)
1781.07654321E-9
179int(13)
180
181-- Iteration 9 --
1820.5
183int(3)
1840.5
185int(3)
1860.5
187int(3)
188
189-- Iteration 10 --
190
191Notice: Array to string conversion in %s on line %d
192Array
193int(5)
194
195Notice: Array to string conversion in %s on line %d
196Array
197int(5)
198
199Notice: Array to string conversion in %s on line %d
200Array
201int(5)
202
203-- Iteration 11 --
204
205Notice: Array to string conversion in %s on line %d
206Array
207int(5)
208
209Notice: Array to string conversion in %s on line %d
210Array
211int(5)
212
213Notice: Array to string conversion in %s on line %d
214Array
215int(5)
216
217-- Iteration 12 --
218
219Notice: Array to string conversion in %s on line %d
220Array
221int(5)
222
223Notice: Array to string conversion in %s on line %d
224Array
225int(5)
226
227Notice: Array to string conversion in %s on line %d
228Array
229int(5)
230
231-- Iteration 13 --
232
233Notice: Array to string conversion in %s on line %d
234Array
235int(5)
236
237Notice: Array to string conversion in %s on line %d
238Array
239int(5)
240
241Notice: Array to string conversion in %s on line %d
242Array
243int(5)
244
245-- Iteration 14 --
246
247Notice: Array to string conversion in %s on line %d
248Array
249int(5)
250
251Notice: Array to string conversion in %s on line %d
252Array
253int(5)
254
255Notice: Array to string conversion in %s on line %d
256Array
257int(5)
258
259-- Iteration 15 --
260
261int(0)
262
263int(0)
264
265int(0)
266
267-- Iteration 16 --
268
269int(0)
270
271int(0)
272
273int(0)
274
275-- Iteration 17 --
2761
277int(1)
2781
279int(1)
2801
281int(1)
282
283-- Iteration 18 --
284
285int(0)
286
287int(0)
288
289int(0)
290
291-- Iteration 19 --
2921
293int(1)
2941
295int(1)
2961
297int(1)
298
299-- Iteration 20 --
300
301int(0)
302
303int(0)
304
305int(0)
306
307-- Iteration 21 --
308
309int(0)
310
311int(0)
312
313int(0)
314
315-- Iteration 22 --
316
317int(0)
318
319int(0)
320
321int(0)
322
323-- Iteration 23 --
324Object
325int(6)
326Object
327int(6)
328Object
329int(6)
330
331-- Iteration 24 --
332
333int(0)
334
335int(0)
336
337int(0)
338
339-- Iteration 25 --
340
341int(0)
342
343int(0)
344
345int(0)
346
347-- Iteration 26 --
348Resource id #%d
349int(%d)
350Resource id #%d
351int(%d)
352Resource id #%d
353int(%d)
354===DONE===
355