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