1--TEST-- 2Test array_intersect() function : usage variations - unexpected values for 'array2' argument 3--FILE-- 4<?php 5/* 6* Testing array_intersect() function by passing values to $array2 argument other than arrays 7* and see that function emits proper warning messages wherever expected. 8* The $array1 argument is a fixed array. 9*/ 10 11echo "*** Testing array_intersect() : Passing non-array values to \$array2 argument ***\n"; 12 13// array to be passsed to $array1 as default argument 14$array1 = array(1, 2); 15 16// arrays 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 $array2 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($array1,$unexpected_value) ); 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($array1, $unexpected_value, $arr3) ); 102 } catch (TypeError $e) { 103 echo $e->getMessage(), "\n"; 104 } 105 106 $iterator++; 107} 108 109// close the file resource used 110fclose($fp); 111 112echo "Done"; 113?> 114--EXPECT-- 115*** Testing array_intersect() : Passing non-array values to $array2 argument *** 116 117-- Iterator 1 --array_intersect(): Argument #2 must be of type array, int given 118array_intersect(): Argument #2 must be of type array, int given 119 120-- Iterator 2 --array_intersect(): Argument #2 must be of type array, int given 121array_intersect(): Argument #2 must be of type array, int given 122 123-- Iterator 3 --array_intersect(): Argument #2 must be of type array, int given 124array_intersect(): Argument #2 must be of type array, int given 125 126-- Iterator 4 --array_intersect(): Argument #2 must be of type array, int given 127array_intersect(): Argument #2 must be of type array, int given 128 129-- Iterator 5 --array_intersect(): Argument #2 must be of type array, float given 130array_intersect(): Argument #2 must be of type array, float given 131 132-- Iterator 6 --array_intersect(): Argument #2 must be of type array, float given 133array_intersect(): Argument #2 must be of type array, float given 134 135-- Iterator 7 --array_intersect(): Argument #2 must be of type array, float given 136array_intersect(): Argument #2 must be of type array, float given 137 138-- Iterator 8 --array_intersect(): Argument #2 must be of type array, float given 139array_intersect(): Argument #2 must be of type array, float given 140 141-- Iterator 9 --array_intersect(): Argument #2 must be of type array, float given 142array_intersect(): Argument #2 must be of type array, float given 143 144-- Iterator 10 --array_intersect(): Argument #2 must be of type array, null given 145array_intersect(): Argument #2 must be of type array, null given 146 147-- Iterator 11 --array_intersect(): Argument #2 must be of type array, null given 148array_intersect(): Argument #2 must be of type array, null given 149 150-- Iterator 12 --array_intersect(): Argument #2 must be of type array, true given 151array_intersect(): Argument #2 must be of type array, true given 152 153-- Iterator 13 --array_intersect(): Argument #2 must be of type array, false given 154array_intersect(): Argument #2 must be of type array, false given 155 156-- Iterator 14 --array_intersect(): Argument #2 must be of type array, true given 157array_intersect(): Argument #2 must be of type array, true given 158 159-- Iterator 15 --array_intersect(): Argument #2 must be of type array, false given 160array_intersect(): Argument #2 must be of type array, false given 161 162-- Iterator 16 --array_intersect(): Argument #2 must be of type array, string given 163array_intersect(): Argument #2 must be of type array, string given 164 165-- Iterator 17 --array_intersect(): Argument #2 must be of type array, string given 166array_intersect(): Argument #2 must be of type array, string given 167 168-- Iterator 18 --array_intersect(): Argument #2 must be of type array, string given 169array_intersect(): Argument #2 must be of type array, string given 170 171-- Iterator 19 --array_intersect(): Argument #2 must be of type array, string given 172array_intersect(): Argument #2 must be of type array, string given 173 174-- Iterator 20 --array_intersect(): Argument #2 must be of type array, string given 175array_intersect(): Argument #2 must be of type array, string given 176 177-- Iterator 21 --array_intersect(): Argument #2 must be of type array, classA given 178array_intersect(): Argument #2 must be of type array, classA given 179 180-- Iterator 22 --array_intersect(): Argument #2 must be of type array, null given 181array_intersect(): Argument #2 must be of type array, null given 182 183-- Iterator 23 --array_intersect(): Argument #2 must be of type array, null given 184array_intersect(): Argument #2 must be of type array, null given 185 186-- Iterator 24 --array_intersect(): Argument #2 must be of type array, resource given 187array_intersect(): Argument #2 must be of type array, resource given 188Done 189