1--TEST-- 2Test array_intersect() function : usage variations - unexpected values for 'array1' argument 3--FILE-- 4<?php 5/* 6* Testing array_intersect() function by passing values to $array1 argument other than arrays 7* and see that function emits proper warning messages wherever expected. 8* The $array2 argument is a fixed array. 9*/ 10 11echo "*** Testing array_intersect() : Passing non-array values to \$array1 argument ***\n"; 12 13// array to be passsed to $array2 as default argument 14$array2 = array(1, 2); 15 16// array to be passed to optional argument 17$arr3 = array(1, 2, "one" => 1, "two" => 2); 18 19// get an unset variable 20$unset_var = 10; 21unset ($unset_var); 22 23// get a class 24class classA 25{ 26 public function __toString() { 27 return "Class A object"; 28 } 29} 30 31// heredoc string 32$heredoc = <<<EOT 33hello world 34EOT; 35 36// get a resource variable 37$fp = fopen(__FILE__, "r"); 38 39// unexpected values to be passed to $array1 argument 40$arrays = array( 41 42 // int data 43/*1*/ 0, 44 1, 45 12345, 46 -2345, 47 48 // float data 49/*5*/ 10.5, 50 -10.5, 51 12.3456789000e10, 52 12.3456789000E-10, 53 .5, 54 55 // null data 56/*10*/ NULL, 57 null, 58 59 // boolean data 60/*12*/ true, 61 false, 62 TRUE, 63 FALSE, 64 65 // empty data 66/*16*/ "", 67 '', 68 69 // string data 70/*18*/ "string", 71 'string', 72 $heredoc, 73 74 // object data 75/*21*/ new classA(), 76 77 // undefined data 78/*22*/ @$undefined_var, 79 80 // unset data 81/*23*/ @$unset_var, 82 83 // resource variable 84/*24*/ $fp 85); 86 87// loop through each sub-array within $arrays to check the behavior of array_intersect() 88$iterator = 1; 89foreach($arrays as $unexpected_value) { 90 echo "\n-- Iterator $iterator --"; 91 92 // Calling array_intersect() with default arguments 93 try { 94 var_dump( array_intersect($unexpected_value,$array2) ); 95 } catch (TypeError $e) { 96 echo $e->getMessage(), "\n"; 97 } 98 99 // Calling array_intersect() with more arguments 100 try { 101 var_dump( array_intersect($unexpected_value, $array2, $arr3) ); 102 } catch (TypeError $e) { 103 echo $e->getMessage(), "\n"; 104 } 105 $iterator++; 106} 107 108// close the file resource used 109fclose($fp); 110 111echo "Done"; 112?> 113--EXPECT-- 114*** Testing array_intersect() : Passing non-array values to $array1 argument *** 115 116-- Iterator 1 --array_intersect(): Argument #1 ($array) must be of type array, int given 117array_intersect(): Argument #1 ($array) must be of type array, int given 118 119-- Iterator 2 --array_intersect(): Argument #1 ($array) must be of type array, int given 120array_intersect(): Argument #1 ($array) must be of type array, int given 121 122-- Iterator 3 --array_intersect(): Argument #1 ($array) must be of type array, int given 123array_intersect(): Argument #1 ($array) must be of type array, int given 124 125-- Iterator 4 --array_intersect(): Argument #1 ($array) must be of type array, int given 126array_intersect(): Argument #1 ($array) must be of type array, int given 127 128-- Iterator 5 --array_intersect(): Argument #1 ($array) must be of type array, float given 129array_intersect(): Argument #1 ($array) must be of type array, float given 130 131-- Iterator 6 --array_intersect(): Argument #1 ($array) must be of type array, float given 132array_intersect(): Argument #1 ($array) must be of type array, float given 133 134-- Iterator 7 --array_intersect(): Argument #1 ($array) must be of type array, float given 135array_intersect(): Argument #1 ($array) must be of type array, float given 136 137-- Iterator 8 --array_intersect(): Argument #1 ($array) must be of type array, float given 138array_intersect(): Argument #1 ($array) must be of type array, float given 139 140-- Iterator 9 --array_intersect(): Argument #1 ($array) must be of type array, float given 141array_intersect(): Argument #1 ($array) must be of type array, float given 142 143-- Iterator 10 --array_intersect(): Argument #1 ($array) must be of type array, null given 144array_intersect(): Argument #1 ($array) must be of type array, null given 145 146-- Iterator 11 --array_intersect(): Argument #1 ($array) must be of type array, null given 147array_intersect(): Argument #1 ($array) must be of type array, null given 148 149-- Iterator 12 --array_intersect(): Argument #1 ($array) must be of type array, true given 150array_intersect(): Argument #1 ($array) must be of type array, true given 151 152-- Iterator 13 --array_intersect(): Argument #1 ($array) must be of type array, false given 153array_intersect(): Argument #1 ($array) must be of type array, false given 154 155-- Iterator 14 --array_intersect(): Argument #1 ($array) must be of type array, true given 156array_intersect(): Argument #1 ($array) must be of type array, true given 157 158-- Iterator 15 --array_intersect(): Argument #1 ($array) must be of type array, false given 159array_intersect(): Argument #1 ($array) must be of type array, false given 160 161-- Iterator 16 --array_intersect(): Argument #1 ($array) must be of type array, string given 162array_intersect(): Argument #1 ($array) must be of type array, string given 163 164-- Iterator 17 --array_intersect(): Argument #1 ($array) must be of type array, string given 165array_intersect(): Argument #1 ($array) must be of type array, string given 166 167-- Iterator 18 --array_intersect(): Argument #1 ($array) must be of type array, string given 168array_intersect(): Argument #1 ($array) must be of type array, string given 169 170-- Iterator 19 --array_intersect(): Argument #1 ($array) must be of type array, string given 171array_intersect(): Argument #1 ($array) must be of type array, string given 172 173-- Iterator 20 --array_intersect(): Argument #1 ($array) must be of type array, string given 174array_intersect(): Argument #1 ($array) must be of type array, string given 175 176-- Iterator 21 --array_intersect(): Argument #1 ($array) must be of type array, classA given 177array_intersect(): Argument #1 ($array) must be of type array, classA given 178 179-- Iterator 22 --array_intersect(): Argument #1 ($array) must be of type array, null given 180array_intersect(): Argument #1 ($array) must be of type array, null given 181 182-- Iterator 23 --array_intersect(): Argument #1 ($array) must be of type array, null given 183array_intersect(): Argument #1 ($array) must be of type array, null given 184 185-- Iterator 24 --array_intersect(): Argument #1 ($array) must be of type array, resource given 186array_intersect(): Argument #1 ($array) must be of type array, resource given 187Done 188