1--TEST-- 2Test array_diff_assoc() function : usage variations - unexpected values for 'array1' argument 3--FILE-- 4<?php 5/* 6 * Pass array_diff_assoc arguments that are not arrays in place of $array1 7 */ 8 9echo "*** Testing array_diff_assoc() : usage variations ***\n"; 10 11$array = array(1, 2, 3); 12 13//get an unset variable 14$unset_var = 10; 15unset ($unset_var); 16 17// get a class 18class classA 19{ 20 public function __toString() { 21 return "Class A object"; 22 } 23} 24 25// heredoc string 26$heredoc = <<<EOT 27hello world 28EOT; 29 30// get a resource variable 31$fp = fopen(__FILE__, "r"); 32 33//array of unexpected values to be passed to $array1 argument 34$inputs = array( 35 36 // int data 37/*1*/ 0, 38 1, 39 12345, 40 -2345, 41 42 // float data 43/*5*/ 10.5, 44 -10.5, 45 12.3456789000e10, 46 12.3456789000E-10, 47 .5, 48 49 // null data 50/*10*/ NULL, 51 null, 52 53 // boolean data 54/*12*/ true, 55 false, 56 TRUE, 57 FALSE, 58 59 // empty data 60/*16*/ "", 61 '', 62 63 // string data 64/*18*/ "string", 65 'string', 66 $heredoc, 67 68 // binary data 69/*21*/ b"binary", 70 (binary)"binary", 71 72 // object data 73/*23*/ new classA(), 74 75 // undefined data 76/*24*/ @$undefined_var, 77 78 // unset data 79/*25*/ @$unset_var, 80 81 // resource variable 82/*26*/ $fp, 83); 84 85// loop through each element of $inputs to check the behavior of array_diff_assoc 86$iterator = 1; 87foreach($inputs as $input) { 88 echo "\n-- Iteration $iterator --\n"; 89 try { 90 var_dump(array_diff_assoc($input, $array)); 91 } catch (TypeError $e) { 92 echo $e->getMessage(), "\n"; 93 } 94 $iterator++; 95}; 96fclose($fp); 97echo "Done"; 98?> 99--EXPECT-- 100*** Testing array_diff_assoc() : usage variations *** 101 102-- Iteration 1 -- 103array_diff_assoc(): Argument #1 ($array) must be of type array, int given 104 105-- Iteration 2 -- 106array_diff_assoc(): Argument #1 ($array) must be of type array, int given 107 108-- Iteration 3 -- 109array_diff_assoc(): Argument #1 ($array) must be of type array, int given 110 111-- Iteration 4 -- 112array_diff_assoc(): Argument #1 ($array) must be of type array, int given 113 114-- Iteration 5 -- 115array_diff_assoc(): Argument #1 ($array) must be of type array, float given 116 117-- Iteration 6 -- 118array_diff_assoc(): Argument #1 ($array) must be of type array, float given 119 120-- Iteration 7 -- 121array_diff_assoc(): Argument #1 ($array) must be of type array, float given 122 123-- Iteration 8 -- 124array_diff_assoc(): Argument #1 ($array) must be of type array, float given 125 126-- Iteration 9 -- 127array_diff_assoc(): Argument #1 ($array) must be of type array, float given 128 129-- Iteration 10 -- 130array_diff_assoc(): Argument #1 ($array) must be of type array, null given 131 132-- Iteration 11 -- 133array_diff_assoc(): Argument #1 ($array) must be of type array, null given 134 135-- Iteration 12 -- 136array_diff_assoc(): Argument #1 ($array) must be of type array, true given 137 138-- Iteration 13 -- 139array_diff_assoc(): Argument #1 ($array) must be of type array, false given 140 141-- Iteration 14 -- 142array_diff_assoc(): Argument #1 ($array) must be of type array, true given 143 144-- Iteration 15 -- 145array_diff_assoc(): Argument #1 ($array) must be of type array, false given 146 147-- Iteration 16 -- 148array_diff_assoc(): Argument #1 ($array) must be of type array, string given 149 150-- Iteration 17 -- 151array_diff_assoc(): Argument #1 ($array) must be of type array, string given 152 153-- Iteration 18 -- 154array_diff_assoc(): Argument #1 ($array) must be of type array, string given 155 156-- Iteration 19 -- 157array_diff_assoc(): Argument #1 ($array) must be of type array, string given 158 159-- Iteration 20 -- 160array_diff_assoc(): Argument #1 ($array) must be of type array, string given 161 162-- Iteration 21 -- 163array_diff_assoc(): Argument #1 ($array) must be of type array, string given 164 165-- Iteration 22 -- 166array_diff_assoc(): Argument #1 ($array) must be of type array, string given 167 168-- Iteration 23 -- 169array_diff_assoc(): Argument #1 ($array) must be of type array, classA given 170 171-- Iteration 24 -- 172array_diff_assoc(): Argument #1 ($array) must be of type array, null given 173 174-- Iteration 25 -- 175array_diff_assoc(): Argument #1 ($array) must be of type array, null given 176 177-- Iteration 26 -- 178array_diff_assoc(): Argument #1 ($array) must be of type array, resource given 179Done 180