1--TEST-- 2Test array_fill() function : usage variations - unexpected values for 'start_key' argument 3--SKIPIF-- 4<?php 5if (PHP_INT_SIZE != 8) die("skip this test is for 64bit 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 -- 127array(2) { 128 [123456789000]=> 129 int(100) 130 [123456789001]=> 131 int(100) 132} 133-- Iteration 4 -- 134array(2) { 135 [0]=> 136 int(100) 137 [1]=> 138 int(100) 139} 140-- Iteration 5 -- 141array(2) { 142 [0]=> 143 int(100) 144 [1]=> 145 int(100) 146} 147-- Iteration 6 -- 148 149Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d 150NULL 151-- Iteration 7 -- 152 153Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d 154NULL 155-- Iteration 8 -- 156 157Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d 158NULL 159-- Iteration 9 -- 160 161Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d 162NULL 163-- Iteration 10 -- 164 165Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d 166NULL 167-- Iteration 11 -- 168array(2) { 169 [0]=> 170 int(100) 171 [1]=> 172 int(100) 173} 174-- Iteration 12 -- 175array(2) { 176 [0]=> 177 int(100) 178 [1]=> 179 int(100) 180} 181-- Iteration 13 -- 182array(2) { 183 [1]=> 184 int(100) 185 [2]=> 186 int(100) 187} 188-- Iteration 14 -- 189array(2) { 190 [0]=> 191 int(100) 192 [1]=> 193 int(100) 194} 195-- Iteration 15 -- 196array(2) { 197 [1]=> 198 int(100) 199 [2]=> 200 int(100) 201} 202-- Iteration 16 -- 203array(2) { 204 [0]=> 205 int(100) 206 [1]=> 207 int(100) 208} 209-- Iteration 17 -- 210 211Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d 212NULL 213-- Iteration 18 -- 214 215Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d 216NULL 217-- Iteration 19 -- 218 219Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d 220NULL 221-- Iteration 20 -- 222 223Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d 224NULL 225-- Iteration 21 -- 226 227Warning: array_fill() expects parameter 1 to be long, object given in %s on line %d 228NULL 229-- Iteration 22 -- 230array(2) { 231 [0]=> 232 int(100) 233 [1]=> 234 int(100) 235} 236-- Iteration 23 -- 237array(2) { 238 [0]=> 239 int(100) 240 [1]=> 241 int(100) 242} 243-- Iteration 24 -- 244 245Warning: array_fill() expects parameter 1 to be long, resource given in %s on line %d 246NULL 247Done 248