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