1--TEST--
2Test vfprintf() function : usage variations - unexpected values for args 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 values are passed to
12 * the '$args' arguments of the function
13*/
14
15echo "*** Testing vfprintf() : with unexpected values for args argument ***\n";
16
17// initialising the required variables
18$format = '%s';
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		  // null data
53/*10*/	  NULL,
54		  null,
55
56		  // boolean data
57/*12*/	  true,
58		  false,
59		  TRUE,
60		  FALSE,
61
62		  // empty data
63/*16*/	  "",
64		  '',
65
66		  // string data
67/*18*/	  "string",
68		  'string',
69
70		  // object data
71/*20*/	  new sample(),
72
73		  // undefined data
74/*21*/	  @$undefined_var,
75
76		  // unset data
77/*22*/	  @$unset_var,
78
79		  // resource data
80/*23*/	  $file_handle
81);
82
83/* creating dumping file */
84$data_file = __DIR__ . '/vfprintf_variation21.txt';
85if (!($fp = fopen($data_file, 'wt')))
86   return;
87
88fprintf($fp, "\n*** Testing vprintf() with unexpected values for args argument ***\n");
89
90$counter = 1;
91foreach( $values as $value ) {
92  fprintf($fp, "\n-- Iteration %d --\n",$counter);
93  vfprintf($fp, $format, $value);
94  $counter++;
95}
96
97fclose($fp);
98print_r(file_get_contents($data_file));
99echo "\n";
100
101unlink($data_file);
102
103
104?>
105===DONE===
106--EXPECTF--
107*** Testing vfprintf() : with unexpected values for args argument ***
108
109Warning: vfprintf(): Too few arguments in %s on line %d
110
111Warning: vfprintf(): Too few arguments in %s on line %d
112
113Warning: vfprintf(): Too few arguments in %s on line %d
114
115Warning: vfprintf(): Too few arguments in %s on line %d
116
117Warning: vfprintf(): Too few arguments in %s on line %d
118
119*** Testing vprintf() with unexpected values for args argument ***
120
121-- Iteration 1 --
1220
123-- Iteration 2 --
1241
125-- Iteration 3 --
12612345
127-- Iteration 4 --
128-2345
129-- Iteration 5 --
13010.5
131-- Iteration 6 --
132-10.5
133-- Iteration 7 --
134101234567000
135-- Iteration 8 --
1361.07654321E-9
137-- Iteration 9 --
1380.5
139-- Iteration 10 --
140
141-- Iteration 11 --
142
143-- Iteration 12 --
1441
145-- Iteration 13 --
146
147-- Iteration 14 --
1481
149-- Iteration 15 --
150
151-- Iteration 16 --
152
153-- Iteration 17 --
154
155-- Iteration 18 --
156string
157-- Iteration 19 --
158string
159-- Iteration 20 --
160
161-- Iteration 21 --
162
163-- Iteration 22 --
164
165-- Iteration 23 --
166Resource id #%d
167===DONE===
168