1--TEST-- 2Test array_diff_uassoc() function : usage variation -Passing unexpected values to second argument 3--FILE-- 4<?php 5echo "*** Testing array_diff_uassoc() : usage variation ***\n"; 6 7//Initialize variables 8$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); 9 10function key_compare_func($a, $b) 11{ 12 if ($a === $b) { 13 return 0; 14 } 15 return ($a > $b)? 1:-1; 16} 17 18//get an unset variable 19$unset_var = 10; 20unset ($unset_var); 21 22//resource variable 23$fp = fopen(__FILE__, "r"); 24 25// define some classes 26class classWithToString 27{ 28 public function __toString() { 29 return "Class A object"; 30 } 31} 32 33class classWithoutToString 34{ 35} 36 37// heredoc string 38$heredoc = <<<EOT 39hello world 40EOT; 41 42// add arrays 43$index_array = array (1, 2, 3); 44$assoc_array = array ('one' => 1, 'two' => 2); 45 46//array of values to iterate over 47$inputs = array( 48 49 // int data 50 'int 0' => 0, 51 'int 1' => 1, 52 'int 12345' => 12345, 53 'int -12345' => -2345, 54 55 // float data 56 'float 10.5' => 10.5, 57 'float -10.5' => -10.5, 58 'float 12.3456789000e10' => 12.3456789000e10, 59 'float -12.3456789000e10' => -12.3456789000e10, 60 'float .5' => .5, 61 62 // null data 63 'uppercase NULL' => NULL, 64 'lowercase null' => null, 65 66 // boolean data 67 'lowercase true' => true, 68 'lowercase false' =>false, 69 'uppercase TRUE' =>TRUE, 70 'uppercase FALSE' =>FALSE, 71 72 // empty data 73 'empty string DQ' => "", 74 'empty string SQ' => '', 75 76 // string data 77 'string DQ' => "string", 78 'string SQ' => 'string', 79 'mixed case string' => "sTrInG", 80 'heredoc' => $heredoc, 81 82 // object data 83 'instance of classWithToString' => new classWithToString(), 84 'instance of classWithoutToString' => new classWithoutToString(), 85 86 // undefined data 87 'undefined var' => @$undefined_var, 88 89 // unset data 90 'unset var' => @$unset_var, 91 92 // resource data 93 'resource' => $fp, 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_uassoc($array1, $value, "key_compare_func") ); 102 } catch (TypeError $e) { 103 echo $e->getMessage(), "\n"; 104 } 105}; 106 107fclose($fp); 108?> 109--EXPECT-- 110*** Testing array_diff_uassoc() : usage variation *** 111 112--int 0-- 113array_diff_uassoc(): Argument #2 must be of type array, int given 114 115--int 1-- 116array_diff_uassoc(): Argument #2 must be of type array, int given 117 118--int 12345-- 119array_diff_uassoc(): Argument #2 must be of type array, int given 120 121--int -12345-- 122array_diff_uassoc(): Argument #2 must be of type array, int given 123 124--float 10.5-- 125array_diff_uassoc(): Argument #2 must be of type array, float given 126 127--float -10.5-- 128array_diff_uassoc(): Argument #2 must be of type array, float given 129 130--float 12.3456789000e10-- 131array_diff_uassoc(): Argument #2 must be of type array, float given 132 133--float -12.3456789000e10-- 134array_diff_uassoc(): Argument #2 must be of type array, float given 135 136--float .5-- 137array_diff_uassoc(): Argument #2 must be of type array, float given 138 139--uppercase NULL-- 140array_diff_uassoc(): Argument #2 must be of type array, null given 141 142--lowercase null-- 143array_diff_uassoc(): Argument #2 must be of type array, null given 144 145--lowercase true-- 146array_diff_uassoc(): Argument #2 must be of type array, bool given 147 148--lowercase false-- 149array_diff_uassoc(): Argument #2 must be of type array, bool given 150 151--uppercase TRUE-- 152array_diff_uassoc(): Argument #2 must be of type array, bool given 153 154--uppercase FALSE-- 155array_diff_uassoc(): Argument #2 must be of type array, bool given 156 157--empty string DQ-- 158array_diff_uassoc(): Argument #2 must be of type array, string given 159 160--empty string SQ-- 161array_diff_uassoc(): Argument #2 must be of type array, string given 162 163--string DQ-- 164array_diff_uassoc(): Argument #2 must be of type array, string given 165 166--string SQ-- 167array_diff_uassoc(): Argument #2 must be of type array, string given 168 169--mixed case string-- 170array_diff_uassoc(): Argument #2 must be of type array, string given 171 172--heredoc-- 173array_diff_uassoc(): Argument #2 must be of type array, string given 174 175--instance of classWithToString-- 176array_diff_uassoc(): Argument #2 must be of type array, classWithToString given 177 178--instance of classWithoutToString-- 179array_diff_uassoc(): Argument #2 must be of type array, classWithoutToString given 180 181--undefined var-- 182array_diff_uassoc(): Argument #2 must be of type array, null given 183 184--unset var-- 185array_diff_uassoc(): Argument #2 must be of type array, null given 186 187--resource-- 188array_diff_uassoc(): Argument #2 must be of type array, resource given 189