1--TEST--
2Test array_fill() function : usage variations  - unexpected values for 'val' argument
3--FILE--
4<?php
5/* Prototype  : 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 'val' argument
12 */
13
14echo "*** Testing array_fill() : usage variations ***\n";
15
16// Initialise function arguments not being substituted
17$start_key = 0;
18$num = 2;
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 'val' argument
36$values = array(
37            // empty string
38  /* 1  */  "",
39            '',
40            // objects
41  /* 3  */  new test(),
42
43            // undefined variable
44            @$undefined_var,
45
46            // unset variable
47  /* 5  */  @$unset_var,
48);
49
50// loop through each element of the array for 'val' argument
51// check the working of array_fill()
52echo "--- Testing array_fill() with different values for 'val' argument ---\n";
53$counter = 1;
54for($index = 0; $index < count($values); $index ++)
55{
56  echo "-- Iteration $counter --\n";
57  $val = $values[$index];
58
59  var_dump( array_fill($start_key , $num , $val) );
60
61  $counter++;
62}
63
64echo"Done";
65?>
66--EXPECTF--
67*** Testing array_fill() : usage variations ***
68--- Testing array_fill() with different values for 'val' argument ---
69-- Iteration 1 --
70array(2) {
71  [0]=>
72  string(0) ""
73  [1]=>
74  string(0) ""
75}
76-- Iteration 2 --
77array(2) {
78  [0]=>
79  string(0) ""
80  [1]=>
81  string(0) ""
82}
83-- Iteration 3 --
84array(2) {
85  [0]=>
86  object(test)#%d (1) {
87    ["t"]=>
88    int(10)
89  }
90  [1]=>
91  object(test)#%d (1) {
92    ["t"]=>
93    int(10)
94  }
95}
96-- Iteration 4 --
97array(2) {
98  [0]=>
99  NULL
100  [1]=>
101  NULL
102}
103-- Iteration 5 --
104array(2) {
105  [0]=>
106  NULL
107  [1]=>
108  NULL
109}
110Done
111