1--TEST--
2Test vfprintf() function : usage variations - unexpected values for the format argument
3--FILE--
4<?php
5/* Prototype  : int vfprintf  ( resource $handle  , string $format , array $args  )
6 * Description: Write a formatted string to a stream
7 * Source code: ext/standard/formatted_print.c
8*/
9
10/*
11 * Test vfprintf() when different unexpected format strings are passed to
12 * the '$format' argument of the function
13*/
14
15echo "*** Testing vfprintf() : 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/* creating dumping file */
87$data_file = dirname(__FILE__) . '/dump.txt';
88if (!($fp = fopen($data_file, 'wt')))
89   return;
90
91fprintf($fp, "\n*** Testing vprintf() with with unexpected values for format argument ***\n");
92
93$counter = 1;
94foreach( $values as $value ) {
95  fprintf( $fp, "\n-- Iteration %d --\n",$counter);
96  vfprintf($fp, $value, $args);
97  $counter++;
98}
99
100fclose($fp);
101print_r(file_get_contents($data_file));
102echo "\n";
103
104unlink($data_file);
105
106?>
107===DONE===
108--EXPECTF--
109*** Testing vfprintf() : with unexpected values for format argument ***
110
111Notice: Array to string conversion in %s on line %d
112
113Notice: Array to string conversion in %s on line %d
114
115Notice: Array to string conversion in %s on line %d
116
117Notice: Array to string conversion in %s on line %d
118
119Notice: Array to string conversion in %s on line %d
120
121*** Testing vprintf() with with unexpected values for format argument ***
122
123-- Iteration 1 --
1240
125-- Iteration 2 --
1261
127-- Iteration 3 --
12812345
129-- Iteration 4 --
130-2345
131-- Iteration 5 --
13210.5
133-- Iteration 6 --
134-10.5
135-- Iteration 7 --
136101234567000
137-- Iteration 8 --
1381.07654321E-9
139-- Iteration 9 --
1400.5
141-- Iteration 10 --
142Array
143-- Iteration 11 --
144Array
145-- Iteration 12 --
146Array
147-- Iteration 13 --
148Array
149-- Iteration 14 --
150Array
151-- Iteration 15 --
152
153-- Iteration 16 --
154
155-- Iteration 17 --
1561
157-- Iteration 18 --
158
159-- Iteration 19 --
1601
161-- Iteration 20 --
162
163-- Iteration 21 --
164
165-- Iteration 22 --
166
167-- Iteration 23 --
168object
169-- Iteration 24 --
170
171-- Iteration 25 --
172
173-- Iteration 26 --
174Resource id #%d
175===DONE===
176