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