1--TEST-- 2Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482) 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 $pad_size argument other than integers 12* and see that function outputs proper warning messages wherever expected. 13* The $input and $pad_value arguments passed are fixed values. 14*/ 15 16echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n"; 17 18// Initialise $input and $pad_value arguments 19$input = array(1, 2); 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//array of values to iterate over 35$pad_sizes = array( 36 37 // float data 38/*1*/ 10.5, 39 -10.5, 40 12.3456789000e10, 41 -12.3456789000e10, 42 12.3456789000E-10, 43 .5, 44 45 // array data 46/*6*/ array(), 47 array(0), 48 array(1), 49 array(1, 2), 50 array('color' => 'red', 'item' => 'pen'), 51 52 // null data 53/*11*/ NULL, 54 null, 55 56 // boolean data 57/*13*/ true, 58 false, 59 TRUE, 60 FALSE, 61 62 // empty data 63/*17*/ "", 64 '', 65 66 // string data 67/*19*/ "string", 68 'string', 69 70 // object data 71/*21*/ new classA(), 72 73 // undefined data 74/*22*/ @$undefined_var, 75 76 // unset data 77/*23*/ @$unset_var, 78); 79 80// loop through each element of $pad_sizes to check the behavior of array_pad() 81$iterator = 1; 82foreach($pad_sizes as $pad_size) { 83 echo "-- Iteration $iterator --\n"; 84 var_dump( array_pad($input, $pad_size, $pad_value) ); 85 $iterator++; 86}; 87 88echo "Done"; 89?> 90--EXPECTF-- 91*** Testing array_pad() : passing non integer values to $pad_size argument *** 92-- Iteration 1 -- 93array(10) { 94 [0]=> 95 int(1) 96 [1]=> 97 int(2) 98 [2]=> 99 int(1) 100 [3]=> 101 int(1) 102 [4]=> 103 int(1) 104 [5]=> 105 int(1) 106 [6]=> 107 int(1) 108 [7]=> 109 int(1) 110 [8]=> 111 int(1) 112 [9]=> 113 int(1) 114} 115-- Iteration 2 -- 116array(10) { 117 [0]=> 118 int(1) 119 [1]=> 120 int(1) 121 [2]=> 122 int(1) 123 [3]=> 124 int(1) 125 [4]=> 126 int(1) 127 [5]=> 128 int(1) 129 [6]=> 130 int(1) 131 [7]=> 132 int(1) 133 [8]=> 134 int(1) 135 [9]=> 136 int(2) 137} 138-- Iteration 3 -- 139 140Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d 141bool(false) 142-- Iteration 4 -- 143 144Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d 145bool(false) 146-- Iteration 5 -- 147array(2) { 148 [0]=> 149 int(1) 150 [1]=> 151 int(2) 152} 153-- Iteration 6 -- 154array(2) { 155 [0]=> 156 int(1) 157 [1]=> 158 int(2) 159} 160-- Iteration 7 -- 161 162Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d 163NULL 164-- Iteration 8 -- 165 166Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d 167NULL 168-- Iteration 9 -- 169 170Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d 171NULL 172-- Iteration 10 -- 173 174Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d 175NULL 176-- Iteration 11 -- 177 178Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d 179NULL 180-- Iteration 12 -- 181array(2) { 182 [0]=> 183 int(1) 184 [1]=> 185 int(2) 186} 187-- Iteration 13 -- 188array(2) { 189 [0]=> 190 int(1) 191 [1]=> 192 int(2) 193} 194-- Iteration 14 -- 195array(2) { 196 [0]=> 197 int(1) 198 [1]=> 199 int(2) 200} 201-- Iteration 15 -- 202array(2) { 203 [0]=> 204 int(1) 205 [1]=> 206 int(2) 207} 208-- Iteration 16 -- 209array(2) { 210 [0]=> 211 int(1) 212 [1]=> 213 int(2) 214} 215-- Iteration 17 -- 216array(2) { 217 [0]=> 218 int(1) 219 [1]=> 220 int(2) 221} 222-- Iteration 18 -- 223 224Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d 225NULL 226-- Iteration 19 -- 227 228Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d 229NULL 230-- Iteration 20 -- 231 232Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d 233NULL 234-- Iteration 21 -- 235 236Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d 237NULL 238-- Iteration 22 -- 239 240Warning: array_pad() expects parameter 2 to be long, object given in %s on line %d 241NULL 242-- Iteration 23 -- 243array(2) { 244 [0]=> 245 int(1) 246 [1]=> 247 int(2) 248} 249-- Iteration 24 -- 250array(2) { 251 [0]=> 252 int(1) 253 [1]=> 254 int(2) 255} 256Done 257