1--TEST-- 2Test array_pad() function : usage variations - unexpected values for 'input' argument 3--FILE-- 4<?php 5/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) 6 * Description: Returns a copy of input array padded with pad_value to size pad_size 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11* Testing array_pad() function by passing values to $input argument other than arrays 12* and see that function outputs proper warning messages wherever expected. 13* The $pad_size and $pad_value arguments passed are fixed values. 14*/ 15 16echo "*** Testing array_pad() : passing non array values to \$input argument ***\n"; 17 18// Initialise $pad_size and $pad_value 19$pad_size = 10; 20$pad_value = 1; 21 22//get an unset variable 23$unset_var = 10; 24unset ($unset_var); 25 26// get a class 27class classA 28{ 29 public function __toString() { 30 return "Class A object"; 31 } 32} 33 34// heredoc string 35$heredoc = <<<EOT 36hello world 37EOT; 38 39// get a resource variable 40$fp = fopen(__FILE__, "r"); 41 42// unexpected values to be passed to $input argument 43$inputs = array( 44 45 // int data 46/*1*/ 0, 47 1, 48 12345, 49 -2345, 50 51 // float data 52/*5*/ 10.5, 53 -10.5, 54 12.3456789000e10, 55 12.3456789000E-10, 56 .5, 57 58 // null data 59/*10*/ NULL, 60 null, 61 62 // boolean data 63/*12*/ true, 64 false, 65 TRUE, 66 FALSE, 67 // empty data 68/*16*/ "", 69 '', 70 71 // string data 72/*18*/ "string", 73 'string', 74 $heredoc, 75 76 // object data 77/*21*/ new classA(), 78 79 // undefined data 80/*22*/ @$undefined_var, 81 82 // unset data 83/*23*/ @$unset_var, 84 85 // resource variable 86/*24*/ $fp 87); 88 89// loop through each element of $inputs to check the behavior of array_pad() 90$iterator = 1; 91foreach($inputs as $input) { 92 echo "\n-- Iteration $iterator --"; 93 var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' 94 var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' 95 $iterator++; 96}; 97 98echo "Done"; 99?> 100--EXPECTF-- 101*** Testing array_pad() : passing non array values to $input argument *** 102 103-- Iteration 1 -- 104Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 105NULL 106 107Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 108NULL 109 110-- Iteration 2 -- 111Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 112NULL 113 114Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 115NULL 116 117-- Iteration 3 -- 118Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 119NULL 120 121Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 122NULL 123 124-- Iteration 4 -- 125Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 126NULL 127 128Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d 129NULL 130 131-- Iteration 5 -- 132Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 133NULL 134 135Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 136NULL 137 138-- Iteration 6 -- 139Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 140NULL 141 142Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 143NULL 144 145-- Iteration 7 -- 146Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 147NULL 148 149Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 150NULL 151 152-- Iteration 8 -- 153Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 154NULL 155 156Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 157NULL 158 159-- Iteration 9 -- 160Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 161NULL 162 163Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d 164NULL 165 166-- Iteration 10 -- 167Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 168NULL 169 170Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 171NULL 172 173-- Iteration 11 -- 174Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 175NULL 176 177Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 178NULL 179 180-- Iteration 12 -- 181Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 182NULL 183 184Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 185NULL 186 187-- Iteration 13 -- 188Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 189NULL 190 191Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 192NULL 193 194-- Iteration 14 -- 195Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 196NULL 197 198Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 199NULL 200 201-- Iteration 15 -- 202Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 203NULL 204 205Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d 206NULL 207 208-- Iteration 16 -- 209Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 210NULL 211 212Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 213NULL 214 215-- Iteration 17 -- 216Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 217NULL 218 219Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 220NULL 221 222-- Iteration 18 -- 223Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 224NULL 225 226Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 227NULL 228 229-- Iteration 19 -- 230Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 231NULL 232 233Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 234NULL 235 236-- Iteration 20 -- 237Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 238NULL 239 240Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d 241NULL 242 243-- Iteration 21 -- 244Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d 245NULL 246 247Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d 248NULL 249 250-- Iteration 22 -- 251Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 252NULL 253 254Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 255NULL 256 257-- Iteration 23 -- 258Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 259NULL 260 261Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d 262NULL 263 264-- Iteration 24 -- 265Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d 266NULL 267 268Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d 269NULL 270Done 271