1--TEST-- 2Test array_intersect_key() function : usage variation - Passing unexpected values to second argument 3--FILE-- 4<?php 5/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) 6 * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. 7 * Source code: ext/standard/array.c 8 */ 9 10echo "*** Testing array_intersect_key() : usage variation ***\n"; 11 12// Initialise function arguments not being substituted (if any) 13$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); 14$array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); 15 16//get an unset variable 17$unset_var = 10; 18unset ($unset_var); 19 20//resource variable 21$fp = fopen(__FILE__, "r"); 22 23// define some classes 24class classWithToString 25{ 26 public function __toString() { 27 return "Class A object"; 28 } 29} 30 31class classWithoutToString 32{ 33} 34 35// heredoc string 36$heredoc = <<<EOT 37hello world 38EOT; 39 40// add arrays 41$index_array = array (1, 2, 3); 42$assoc_array = array ('one' => 1, 'two' => 2); 43 44//array of values to iterate over 45$inputs = array( 46 47 // int data 48 'int 0' => 0, 49 'int 1' => 1, 50 'int 12345' => 12345, 51 'int -12345' => -12345, 52 53 // float data 54 'float 10.5' => 10.5, 55 'float -10.5' => -10.5, 56 'float 12.3456789000e10' => 12.3456789000e10, 57 'float -12.3456789000e10' => -12.3456789000e10, 58 'float .5' => .5, 59 60 // null data 61 'uppercase NULL' => NULL, 62 'lowercase null' => null, 63 64 // boolean data 65 'lowercase true' => true, 66 'lowercase false' =>false, 67 'uppercase TRUE' =>TRUE, 68 'uppercase FALSE' =>FALSE, 69 70 // empty data 71 'empty string DQ' => "", 72 'empty string SQ' => '', 73 74 // string data 75 'string DQ' => "string", 76 'string SQ' => 'string', 77 'mixed case string' => "sTrInG", 78 'heredoc' => $heredoc, 79 80 // object data 81 'instance of classWithToString' => new classWithToString(), 82 'instance of classWithoutToString' => new classWithoutToString(), 83 84 // undefined data 85 'undefined var' => @$undefined_var, 86 87 // unset data 88 'unset var' => @$unset_var, 89 90 // resource data 91 'resource var' => $fp, 92); 93 94// loop through each element of the array for arr2 95 96foreach($inputs as $key =>$value) { 97 echo "\n--$key--\n"; 98 var_dump( array_intersect_key($array1, $value) ); 99 var_dump( array_intersect_key($array1, $value, $array3) ); 100} 101 102fclose($fp); 103?> 104===DONE=== 105--EXPECTF-- 106*** Testing array_intersect_key() : usage variation *** 107 108--int 0-- 109 110Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 111NULL 112 113Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 114NULL 115 116--int 1-- 117 118Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 119NULL 120 121Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 122NULL 123 124--int 12345-- 125 126Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 127NULL 128 129Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 130NULL 131 132--int -12345-- 133 134Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 135NULL 136 137Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 138NULL 139 140--float 10.5-- 141 142Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 143NULL 144 145Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 146NULL 147 148--float -10.5-- 149 150Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 151NULL 152 153Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 154NULL 155 156--float 12.3456789000e10-- 157 158Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 159NULL 160 161Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 162NULL 163 164--float -12.3456789000e10-- 165 166Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 167NULL 168 169Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 170NULL 171 172--float .5-- 173 174Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 175NULL 176 177Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 178NULL 179 180--uppercase NULL-- 181 182Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 183NULL 184 185Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 186NULL 187 188--lowercase null-- 189 190Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 191NULL 192 193Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 194NULL 195 196--lowercase true-- 197 198Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 199NULL 200 201Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 202NULL 203 204--lowercase false-- 205 206Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 207NULL 208 209Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 210NULL 211 212--uppercase TRUE-- 213 214Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 215NULL 216 217Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 218NULL 219 220--uppercase FALSE-- 221 222Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 223NULL 224 225Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 226NULL 227 228--empty string DQ-- 229 230Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 231NULL 232 233Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 234NULL 235 236--empty string SQ-- 237 238Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 239NULL 240 241Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 242NULL 243 244--string DQ-- 245 246Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 247NULL 248 249Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 250NULL 251 252--string SQ-- 253 254Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 255NULL 256 257Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 258NULL 259 260--mixed case string-- 261 262Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 263NULL 264 265Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 266NULL 267 268--heredoc-- 269 270Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 271NULL 272 273Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 274NULL 275 276--instance of classWithToString-- 277 278Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 279NULL 280 281Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 282NULL 283 284--instance of classWithoutToString-- 285 286Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 287NULL 288 289Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 290NULL 291 292--undefined var-- 293 294Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 295NULL 296 297Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 298NULL 299 300--unset var-- 301 302Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 303NULL 304 305Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 306NULL 307 308--resource var-- 309 310Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 311NULL 312 313Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d 314NULL 315===DONE=== 316