1--TEST-- 2Test array_diff_key() function : usage variation - Passing unexpected values to third optional 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('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); 14$array2 = 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//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, $array2, $value) ); 95}; 96 97fclose($fp); 98?> 99===DONE=== 100--EXPECTF-- 101*** Testing array_diff_key() : usage variation *** 102 103--int 0-- 104 105Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 106NULL 107 108--int 1-- 109 110Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 111NULL 112 113--int 12345-- 114 115Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 116NULL 117 118--int -12345-- 119 120Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 121NULL 122 123--float 10.5-- 124 125Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 126NULL 127 128--float -10.5-- 129 130Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 131NULL 132 133--float 12.3456789000e10-- 134 135Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 136NULL 137 138--float -12.3456789000e10-- 139 140Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 141NULL 142 143--float .5-- 144 145Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 146NULL 147 148--uppercase NULL-- 149 150Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 151NULL 152 153--lowercase null-- 154 155Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 156NULL 157 158--lowercase true-- 159 160Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 161NULL 162 163--lowercase false-- 164 165Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 166NULL 167 168--uppercase TRUE-- 169 170Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 171NULL 172 173--uppercase FALSE-- 174 175Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 176NULL 177 178--empty string DQ-- 179 180Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 181NULL 182 183--empty string SQ-- 184 185Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 186NULL 187 188--string DQ-- 189 190Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 191NULL 192 193--string SQ-- 194 195Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 196NULL 197 198--mixed case string-- 199 200Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 201NULL 202 203--heredoc-- 204 205Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 206NULL 207 208--instance of classWithToString-- 209 210Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 211NULL 212 213--instance of classWithoutToString-- 214 215Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 216NULL 217 218--undefined var-- 219 220Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 221NULL 222 223--unset var-- 224 225Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 226NULL 227 228--resource-- 229 230Warning: array_diff_key(): Argument #3 is not an array in %s on line %d 231NULL 232===DONE===