1--TEST-- 2Test array_intersect_key() function : usage variation - Passing unexpected values to second argument 3--FILE-- 4<?php 5echo "*** Testing array_intersect_key() : usage variation ***\n"; 6 7// Initialise function arguments not being substituted (if any) 8$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); 9$array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); 10 11//get an unset variable 12$unset_var = 10; 13unset ($unset_var); 14 15//resource variable 16$fp = fopen(__FILE__, "r"); 17 18// define some classes 19class classWithToString 20{ 21 public function __toString() { 22 return "Class A object"; 23 } 24} 25 26class classWithoutToString 27{ 28} 29 30// heredoc string 31$heredoc = <<<EOT 32hello world 33EOT; 34 35// add arrays 36$index_array = array (1, 2, 3); 37$assoc_array = array ('one' => 1, 'two' => 2); 38 39//array of values to iterate over 40$inputs = array( 41 42 // int data 43 'int 0' => 0, 44 'int 1' => 1, 45 'int 12345' => 12345, 46 'int -12345' => -12345, 47 48 // float data 49 'float 10.5' => 10.5, 50 'float -10.5' => -10.5, 51 'float 12.3456789000e10' => 12.3456789000e10, 52 'float -12.3456789000e10' => -12.3456789000e10, 53 'float .5' => .5, 54 55 // null data 56 'uppercase NULL' => NULL, 57 'lowercase null' => null, 58 59 // boolean data 60 'lowercase true' => true, 61 'lowercase false' =>false, 62 'uppercase TRUE' =>TRUE, 63 'uppercase FALSE' =>FALSE, 64 65 // empty data 66 'empty string DQ' => "", 67 'empty string SQ' => '', 68 69 // string data 70 'string DQ' => "string", 71 'string SQ' => 'string', 72 'mixed case string' => "sTrInG", 73 'heredoc' => $heredoc, 74 75 // object data 76 'instance of classWithToString' => new classWithToString(), 77 'instance of classWithoutToString' => new classWithoutToString(), 78 79 // undefined data 80 'undefined var' => @$undefined_var, 81 82 // unset data 83 'unset var' => @$unset_var, 84 85 // resource data 86 'resource var' => $fp, 87); 88 89// loop through each element of the array for array2 90 91foreach($inputs as $key =>$value) { 92 echo "\n--$key--\n"; 93 try { 94 var_dump( array_intersect_key($array1, $value) ); 95 } catch (TypeError $e) { 96 echo $e->getMessage(), "\n"; 97 } 98 try { 99 var_dump( array_intersect_key($array1, $value, $array3) ); 100 } catch (TypeError $e) { 101 echo $e->getMessage(), "\n"; 102 } 103} 104 105fclose($fp); 106?> 107--EXPECT-- 108*** Testing array_intersect_key() : usage variation *** 109 110--int 0-- 111array_intersect_key(): Argument #2 must be of type array, int given 112array_intersect_key(): Argument #2 must be of type array, int given 113 114--int 1-- 115array_intersect_key(): Argument #2 must be of type array, int given 116array_intersect_key(): Argument #2 must be of type array, int given 117 118--int 12345-- 119array_intersect_key(): Argument #2 must be of type array, int given 120array_intersect_key(): Argument #2 must be of type array, int given 121 122--int -12345-- 123array_intersect_key(): Argument #2 must be of type array, int given 124array_intersect_key(): Argument #2 must be of type array, int given 125 126--float 10.5-- 127array_intersect_key(): Argument #2 must be of type array, float given 128array_intersect_key(): Argument #2 must be of type array, float given 129 130--float -10.5-- 131array_intersect_key(): Argument #2 must be of type array, float given 132array_intersect_key(): Argument #2 must be of type array, float given 133 134--float 12.3456789000e10-- 135array_intersect_key(): Argument #2 must be of type array, float given 136array_intersect_key(): Argument #2 must be of type array, float given 137 138--float -12.3456789000e10-- 139array_intersect_key(): Argument #2 must be of type array, float given 140array_intersect_key(): Argument #2 must be of type array, float given 141 142--float .5-- 143array_intersect_key(): Argument #2 must be of type array, float given 144array_intersect_key(): Argument #2 must be of type array, float given 145 146--uppercase NULL-- 147array_intersect_key(): Argument #2 must be of type array, null given 148array_intersect_key(): Argument #2 must be of type array, null given 149 150--lowercase null-- 151array_intersect_key(): Argument #2 must be of type array, null given 152array_intersect_key(): Argument #2 must be of type array, null given 153 154--lowercase true-- 155array_intersect_key(): Argument #2 must be of type array, true given 156array_intersect_key(): Argument #2 must be of type array, true given 157 158--lowercase false-- 159array_intersect_key(): Argument #2 must be of type array, false given 160array_intersect_key(): Argument #2 must be of type array, false given 161 162--uppercase TRUE-- 163array_intersect_key(): Argument #2 must be of type array, true given 164array_intersect_key(): Argument #2 must be of type array, true given 165 166--uppercase FALSE-- 167array_intersect_key(): Argument #2 must be of type array, false given 168array_intersect_key(): Argument #2 must be of type array, false given 169 170--empty string DQ-- 171array_intersect_key(): Argument #2 must be of type array, string given 172array_intersect_key(): Argument #2 must be of type array, string given 173 174--empty string SQ-- 175array_intersect_key(): Argument #2 must be of type array, string given 176array_intersect_key(): Argument #2 must be of type array, string given 177 178--string DQ-- 179array_intersect_key(): Argument #2 must be of type array, string given 180array_intersect_key(): Argument #2 must be of type array, string given 181 182--string SQ-- 183array_intersect_key(): Argument #2 must be of type array, string given 184array_intersect_key(): Argument #2 must be of type array, string given 185 186--mixed case string-- 187array_intersect_key(): Argument #2 must be of type array, string given 188array_intersect_key(): Argument #2 must be of type array, string given 189 190--heredoc-- 191array_intersect_key(): Argument #2 must be of type array, string given 192array_intersect_key(): Argument #2 must be of type array, string given 193 194--instance of classWithToString-- 195array_intersect_key(): Argument #2 must be of type array, classWithToString given 196array_intersect_key(): Argument #2 must be of type array, classWithToString given 197 198--instance of classWithoutToString-- 199array_intersect_key(): Argument #2 must be of type array, classWithoutToString given 200array_intersect_key(): Argument #2 must be of type array, classWithoutToString given 201 202--undefined var-- 203array_intersect_key(): Argument #2 must be of type array, null given 204array_intersect_key(): Argument #2 must be of type array, null given 205 206--unset var-- 207array_intersect_key(): Argument #2 must be of type array, null given 208array_intersect_key(): Argument #2 must be of type array, null given 209 210--resource var-- 211array_intersect_key(): Argument #2 must be of type array, resource given 212array_intersect_key(): Argument #2 must be of type array, resource given 213