1--TEST--
2Test array_fill() function : usage variations  - unexpected values for 'num' argument
3--FILE--
4<?php
5/* Prototype  : proto array array_fill(int start_key, int num, mixed val)
6 * Description: Create an array containing num elements starting with index start_key each initialized to val
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * testing array_fill() by passing different unexpected values for 'num' argument
12 */
13
14echo "*** Testing array_fill() : usage variations ***\n";
15
16// Initialise function arguments not being substituted
17$start_key = 0;
18$val = 100;
19
20//get an unset variable
21$unset_var = 10;
22unset ($unset_var);
23
24//define a class
25class test
26{
27  var $t = 10;
28  function __toString()
29  {
30    return "testObject";
31  }
32}
33
34
35//array of different  values for 'num' argument
36$values = array(
37
38            // float values
39  /* 1  */  2.5,
40            -2.5,
41            0.5e1,
42            0.5E-1,
43            .5,
44
45            // array values
46  /* 6  */  array(),
47            array(0),
48            array(1),
49            array(1, 2),
50            array('color' => 'red', 'item' => 'pen'),
51
52            // null values
53  /* 11 */  NULL,
54            null,
55
56            // boolean values
57  /* 13 */  true,
58            false,
59            TRUE,
60            FALSE,
61
62            // empty string
63  /* 17 */  "",
64            '',
65
66            // string values
67  /* 19 */  "string",
68            'string',
69
70            // objects
71  /* 21 */  new test(),
72
73            // undefined  variable
74            @$undefined_var,
75
76            // unset variable
77  /* 24 */  @$unset_var,
78
79);
80
81// loop through each element of the array for num
82// check the working of array_fill
83echo "--- Testing array_fill() with different values for 'num' arg ---\n";
84$counter = 1;
85for($index = 0; $index < count($values); $index ++)
86{
87  echo "-- Iteration $counter --\n";
88  $num = $values[$index];
89
90  var_dump( array_fill($start_key,$num,$val) );
91
92  $counter ++;
93}
94
95echo "Done";
96?>
97--EXPECTF--
98*** Testing array_fill() : usage variations ***
99--- Testing array_fill() with different values for 'num' arg ---
100-- Iteration 1 --
101array(2) {
102  [0]=>
103  int(100)
104  [1]=>
105  int(100)
106}
107-- Iteration 2 --
108
109Warning: array_fill(): Number of elements must be positive in %s on line %d
110bool(false)
111-- Iteration 3 --
112array(5) {
113  [0]=>
114  int(100)
115  [1]=>
116  int(100)
117  [2]=>
118  int(100)
119  [3]=>
120  int(100)
121  [4]=>
122  int(100)
123}
124-- Iteration 4 --
125
126Warning: array_fill(): Number of elements must be positive in %s on line %d
127bool(false)
128-- Iteration 5 --
129
130Warning: array_fill(): Number of elements must be positive in %s on line %d
131bool(false)
132-- Iteration 6 --
133
134Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d
135NULL
136-- Iteration 7 --
137
138Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d
139NULL
140-- Iteration 8 --
141
142Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d
143NULL
144-- Iteration 9 --
145
146Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d
147NULL
148-- Iteration 10 --
149
150Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d
151NULL
152-- Iteration 11 --
153
154Warning: array_fill(): Number of elements must be positive in %s on line %d
155bool(false)
156-- Iteration 12 --
157
158Warning: array_fill(): Number of elements must be positive in %s on line %d
159bool(false)
160-- Iteration 13 --
161array(1) {
162  [0]=>
163  int(100)
164}
165-- Iteration 14 --
166
167Warning: array_fill(): Number of elements must be positive in %s on line %d
168bool(false)
169-- Iteration 15 --
170array(1) {
171  [0]=>
172  int(100)
173}
174-- Iteration 16 --
175
176Warning: array_fill(): Number of elements must be positive in %s on line %d
177bool(false)
178-- Iteration 17 --
179
180Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d
181NULL
182-- Iteration 18 --
183
184Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d
185NULL
186-- Iteration 19 --
187
188Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d
189NULL
190-- Iteration 20 --
191
192Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d
193NULL
194-- Iteration 21 --
195
196Warning: array_fill() expects parameter 2 to be long, object given in %s on line %d
197NULL
198-- Iteration 22 --
199
200Warning: array_fill(): Number of elements must be positive in %s on line %d
201bool(false)
202-- Iteration 23 --
203
204Warning: array_fill(): Number of elements must be positive in %s on line %d
205bool(false)
206Done
207