1--TEST-- 2Test array_merge_recursive() function : usage variations - unexpected values for $arr2 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 'arr2' 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 \$arr2 argument ***\n"; 16 17// initialise the first argument 18$arr1 = array(1, array("hello", 'world')); 19 20//get an unset variable 21$unset_var = 10; 22unset($unset_var); 23 24class A 25{ 26// public $var = 10; 27 public function __toString() { 28 return "object"; 29 } 30} 31 32// heredoc string 33$heredoc = <<<EOT 34hello world 35EOT; 36 37// get a resource variable 38$fp = fopen(__FILE__, "r"); 39 40// unexpected values to be passed to $arr2 argument 41$arrays = array ( 42 43 // int data 44/*1*/ 0, 45 1, 46 12345, 47 -2345, 48 49 // float data 50/*5*/ 10.5, 51 -10.5, 52 12.3456789000e10, 53 12.3456789000E-10, 54 .5, 55 56 // null data 57/*10*/ NULL, 58 null, 59 60 // boolean data 61/*12*/ true, 62 false, 63 TRUE, 64 FALSE, 65 66 // empty data 67/*16*/ "", 68 '', 69 70 // string data 71/*18*/ "string", 72 'string', 73 $heredoc, 74 75 // undefined data 76/*21*/ @$undefined_var, 77 78 // unset data 79/*22*/ @$unset_var, 80 81 // resource variable 82/*23*/ $fp, 83 84 // object data 85/*24*/ new A() 86); 87 88// loop through each element of $arrays and check the behavior of array_merge_recursive() 89$iterator = 1; 90foreach($arrays as $arr2) { 91 echo "\n-- Iteration $iterator --"; 92 var_dump( array_merge_recursive($arr1, $arr2) ); 93 $iterator++; 94} 95 96// close the file resource used 97fclose($fp); 98 99echo "Done"; 100?> 101--EXPECTF-- 102*** Testing array_merge_recursive() : Passing non array values to $arr2 argument *** 103 104-- Iteration 1 -- 105Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 106NULL 107 108-- Iteration 2 -- 109Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 110NULL 111 112-- Iteration 3 -- 113Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 114NULL 115 116-- Iteration 4 -- 117Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 118NULL 119 120-- Iteration 5 -- 121Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 122NULL 123 124-- Iteration 6 -- 125Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 126NULL 127 128-- Iteration 7 -- 129Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 130NULL 131 132-- Iteration 8 -- 133Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 134NULL 135 136-- Iteration 9 -- 137Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 138NULL 139 140-- Iteration 10 -- 141Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 142NULL 143 144-- Iteration 11 -- 145Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 146NULL 147 148-- Iteration 12 -- 149Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 150NULL 151 152-- Iteration 13 -- 153Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 154NULL 155 156-- Iteration 14 -- 157Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 158NULL 159 160-- Iteration 15 -- 161Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 162NULL 163 164-- Iteration 16 -- 165Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 166NULL 167 168-- Iteration 17 -- 169Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 170NULL 171 172-- Iteration 18 -- 173Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 174NULL 175 176-- Iteration 19 -- 177Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 178NULL 179 180-- Iteration 20 -- 181Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 182NULL 183 184-- Iteration 21 -- 185Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 186NULL 187 188-- Iteration 22 -- 189Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 190NULL 191 192-- Iteration 23 -- 193Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 194NULL 195 196-- Iteration 24 -- 197Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d 198NULL 199Done 200