1--TEST-- 2Test array_intersect_uassoc() function : usage variation - Passing unexpected values to optional third argument 3--FILE-- 4<?php 5/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) 6 * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function 7 * Source code: ext/standard/array.c 8 */ 9 10echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; 11 12// Initialise function arguments 13$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); 14$array2 = array("a" => "green", "yellow", "red"); 15 16//Callback function 17function key_compare_func($a, $b) { 18 if ($a === $b) { 19 return 0; 20 } 21 return ($a > $b) ? 1 : -1; 22} 23 24//get an unset variable 25$unset_var = 10; 26unset ($unset_var); 27 28//resource variable 29$fp = fopen(__FILE__, "r"); 30 31// define some classes 32class classWithToString 33{ 34 public function __toString() { 35 return "Class A object"; 36 } 37} 38 39class classWithoutToString 40{ 41} 42 43// heredoc string 44$heredoc = <<<EOT 45hello world 46EOT; 47 48// add arrays 49$index_array = array (1, 2, 3); 50$assoc_array = array ('one' => 1, 'two' => 2); 51 52//array of values to iterate over 53$inputs = array( 54 55 // int data 56 'int 0' => 0, 57 'int 1' => 1, 58 'int 12345' => 12345, 59 'int -12345' => -12345, 60 61 // float data 62 'float 10.5' => 10.5, 63 'float -10.5' => -10.5, 64 'float 12.3456789000e10' => 12.3456789000e10, 65 'float -12.3456789000e10' => -12.3456789000e10, 66 'float .5' => .5, 67 68 // null data 69 'uppercase NULL' => NULL, 70 'lowercase null' => null, 71 72 // boolean data 73 'lowercase true' => true, 74 'lowercase false' =>false, 75 'uppercase TRUE' =>TRUE, 76 'uppercase FALSE' =>FALSE, 77 78 // empty data 79 'empty string DQ' => "", 80 'empty string SQ' => '', 81 82 // string data 83 'string DQ' => "string", 84 'string SQ' => 'string', 85 'mixed case string' => "sTrInG", 86 'heredoc' => $heredoc, 87 88 // object data 89 'instance of classWithToString' => new classWithToString(), 90 'instance of classWithoutToString' => new classWithoutToString(), 91 92 // undefined data 93 'undefined var' => @$undefined_var, 94 95 // unset data 96 'unset var' => @$unset_var, 97 98 // resource data 99 'resource' => $fp, 100); 101 102// loop through each element of the array for arr1 103foreach($inputs as $key =>$value) { 104 echo "\n--$key--\n"; 105 var_dump( array_intersect_uassoc($array1, $array2, $value, 'key_compare_func') ); 106}; 107 108fclose($fp); 109?> 110===DONE=== 111--EXPECTF-- 112*** Testing array_intersect_uassoc() : usage variation *** 113 114--int 0-- 115 116Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d 117NULL 118 119--int 1-- 120 121Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d 122NULL 123 124--int 12345-- 125 126Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d 127NULL 128 129--int -12345-- 130 131Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, int given in %s on line %d 132NULL 133 134--float 10.5-- 135 136Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d 137NULL 138 139--float -10.5-- 140 141Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d 142NULL 143 144--float 12.3456789000e10-- 145 146Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d 147NULL 148 149--float -12.3456789000e10-- 150 151Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d 152NULL 153 154--float .5-- 155 156Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, float given in %s on line %d 157NULL 158 159--uppercase NULL-- 160 161Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d 162NULL 163 164--lowercase null-- 165 166Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d 167NULL 168 169--lowercase true-- 170 171Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d 172NULL 173 174--lowercase false-- 175 176Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d 177NULL 178 179--uppercase TRUE-- 180 181Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d 182NULL 183 184--uppercase FALSE-- 185 186Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, bool given in %s on line %d 187NULL 188 189--empty string DQ-- 190 191Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d 192NULL 193 194--empty string SQ-- 195 196Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d 197NULL 198 199--string DQ-- 200 201Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d 202NULL 203 204--string SQ-- 205 206Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d 207NULL 208 209--mixed case string-- 210 211Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d 212NULL 213 214--heredoc-- 215 216Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, string given in %s on line %d 217NULL 218 219--instance of classWithToString-- 220 221Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, object given in %s on line %d 222NULL 223 224--instance of classWithoutToString-- 225 226Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, object given in %s on line %d 227NULL 228 229--undefined var-- 230 231Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d 232NULL 233 234--unset var-- 235 236Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, null given in %s on line %d 237NULL 238 239--resource-- 240 241Warning: array_intersect_uassoc(): Expected parameter 3 to be an array, resource given in %s on line %d 242NULL 243===DONE=== 244