1--TEST-- 2Test array_intersect_key() function : usage variation - Passing unexpected values to first 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$array2 = 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 arr1 95foreach($inputs as $key =>$value) { 96 echo "\n--$key--\n"; 97 var_dump( array_intersect_key($value, $array2) ); 98 var_dump( array_intersect_key($value, $array2, $array3) ); 99} 100 101fclose($fp); 102?> 103===DONE=== 104--EXPECTF-- 105*** Testing array_intersect_key() : usage variation *** 106 107--int 0-- 108 109Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 110NULL 111 112Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 113NULL 114 115--int 1-- 116 117Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 118NULL 119 120Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 121NULL 122 123--int 12345-- 124 125Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 126NULL 127 128Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 129NULL 130 131--int -12345-- 132 133Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 134NULL 135 136Warning: array_intersect_key(): Expected parameter 1 to be an array, int given in %s on line %d 137NULL 138 139--float 10.5-- 140 141Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 142NULL 143 144Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 145NULL 146 147--float -10.5-- 148 149Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 150NULL 151 152Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 153NULL 154 155--float 12.3456789000e10-- 156 157Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 158NULL 159 160Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 161NULL 162 163--float -12.3456789000e10-- 164 165Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 166NULL 167 168Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 169NULL 170 171--float .5-- 172 173Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 174NULL 175 176Warning: array_intersect_key(): Expected parameter 1 to be an array, float given in %s on line %d 177NULL 178 179--uppercase NULL-- 180 181Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 182NULL 183 184Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 185NULL 186 187--lowercase null-- 188 189Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 190NULL 191 192Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 193NULL 194 195--lowercase true-- 196 197Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 198NULL 199 200Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 201NULL 202 203--lowercase false-- 204 205Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 206NULL 207 208Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 209NULL 210 211--uppercase TRUE-- 212 213Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 214NULL 215 216Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 217NULL 218 219--uppercase FALSE-- 220 221Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 222NULL 223 224Warning: array_intersect_key(): Expected parameter 1 to be an array, bool given in %s on line %d 225NULL 226 227--empty string DQ-- 228 229Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 230NULL 231 232Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 233NULL 234 235--empty string SQ-- 236 237Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 238NULL 239 240Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 241NULL 242 243--string DQ-- 244 245Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 246NULL 247 248Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 249NULL 250 251--string SQ-- 252 253Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 254NULL 255 256Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 257NULL 258 259--mixed case string-- 260 261Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 262NULL 263 264Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 265NULL 266 267--heredoc-- 268 269Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 270NULL 271 272Warning: array_intersect_key(): Expected parameter 1 to be an array, string given in %s on line %d 273NULL 274 275--instance of classWithToString-- 276 277Warning: array_intersect_key(): Expected parameter 1 to be an array, object given in %s on line %d 278NULL 279 280Warning: array_intersect_key(): Expected parameter 1 to be an array, object given in %s on line %d 281NULL 282 283--instance of classWithoutToString-- 284 285Warning: array_intersect_key(): Expected parameter 1 to be an array, object given in %s on line %d 286NULL 287 288Warning: array_intersect_key(): Expected parameter 1 to be an array, object given in %s on line %d 289NULL 290 291--undefined var-- 292 293Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 294NULL 295 296Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 297NULL 298 299--unset var-- 300 301Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 302NULL 303 304Warning: array_intersect_key(): Expected parameter 1 to be an array, null given in %s on line %d 305NULL 306 307--resource var-- 308 309Warning: array_intersect_key(): Expected parameter 1 to be an array, resource given in %s on line %d 310NULL 311 312Warning: array_intersect_key(): Expected parameter 1 to be an array, resource given in %s on line %d 313NULL 314===DONE=== 315