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 can't be negative 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 --
125array(0) {
126}
127-- Iteration 5 --
128array(0) {
129}
130-- Iteration 6 --
131
132Warning: array_fill() expects parameter 2 to be integer, array given in %s on line %d
133NULL
134-- Iteration 7 --
135
136Warning: array_fill() expects parameter 2 to be integer, array given in %s on line %d
137NULL
138-- Iteration 8 --
139
140Warning: array_fill() expects parameter 2 to be integer, array given in %s on line %d
141NULL
142-- Iteration 9 --
143
144Warning: array_fill() expects parameter 2 to be integer, array given in %s on line %d
145NULL
146-- Iteration 10 --
147
148Warning: array_fill() expects parameter 2 to be integer, array given in %s on line %d
149NULL
150-- Iteration 11 --
151array(0) {
152}
153-- Iteration 12 --
154array(0) {
155}
156-- Iteration 13 --
157array(1) {
158  [0]=>
159  int(100)
160}
161-- Iteration 14 --
162array(0) {
163}
164-- Iteration 15 --
165array(1) {
166  [0]=>
167  int(100)
168}
169-- Iteration 16 --
170array(0) {
171}
172-- Iteration 17 --
173
174Warning: array_fill() expects parameter 2 to be integer, string given in %s on line %d
175NULL
176-- Iteration 18 --
177
178Warning: array_fill() expects parameter 2 to be integer, string given in %s on line %d
179NULL
180-- Iteration 19 --
181
182Warning: array_fill() expects parameter 2 to be integer, string given in %s on line %d
183NULL
184-- Iteration 20 --
185
186Warning: array_fill() expects parameter 2 to be integer, string given in %s on line %d
187NULL
188-- Iteration 21 --
189
190Warning: array_fill() expects parameter 2 to be integer, object given in %s on line %d
191NULL
192-- Iteration 22 --
193array(0) {
194}
195-- Iteration 23 --
196array(0) {
197}
198Done
199