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