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