1--TEST-- 2Test array_diff() function : usage variations - unexpected values for 'array2' argument 3--FILE-- 4<?php 5/* 6 * Test array_diff by passing non array values in place of $array2 7 */ 8 9echo "*** Testing array_diff() : 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// unexpected values to be passed to $input 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 86$iterator = 1; 87foreach($inputs as $input) { 88 echo "\n-- Iteration $iterator --"; 89 try { 90 var_dump( array_diff($array, $input)); 91 } catch (TypeError $e) { 92 echo $e->getMessage(), "\n"; 93 } 94 $iterator++; 95}; 96fclose($fp); 97echo "Done"; 98?> 99--EXPECT-- 100*** Testing array_diff() : usage variations *** 101 102-- Iteration 1 --array_diff(): Argument #2 must be of type array, int given 103 104-- Iteration 2 --array_diff(): Argument #2 must be of type array, int given 105 106-- Iteration 3 --array_diff(): Argument #2 must be of type array, int given 107 108-- Iteration 4 --array_diff(): Argument #2 must be of type array, int given 109 110-- Iteration 5 --array_diff(): Argument #2 must be of type array, float given 111 112-- Iteration 6 --array_diff(): Argument #2 must be of type array, float given 113 114-- Iteration 7 --array_diff(): Argument #2 must be of type array, float given 115 116-- Iteration 8 --array_diff(): Argument #2 must be of type array, float given 117 118-- Iteration 9 --array_diff(): Argument #2 must be of type array, float given 119 120-- Iteration 10 --array_diff(): Argument #2 must be of type array, null given 121 122-- Iteration 11 --array_diff(): Argument #2 must be of type array, null given 123 124-- Iteration 12 --array_diff(): Argument #2 must be of type array, bool given 125 126-- Iteration 13 --array_diff(): Argument #2 must be of type array, bool given 127 128-- Iteration 14 --array_diff(): Argument #2 must be of type array, bool given 129 130-- Iteration 15 --array_diff(): Argument #2 must be of type array, bool given 131 132-- Iteration 16 --array_diff(): Argument #2 must be of type array, string given 133 134-- Iteration 17 --array_diff(): Argument #2 must be of type array, string given 135 136-- Iteration 18 --array_diff(): Argument #2 must be of type array, string given 137 138-- Iteration 19 --array_diff(): Argument #2 must be of type array, string given 139 140-- Iteration 20 --array_diff(): Argument #2 must be of type array, string given 141 142-- Iteration 21 --array_diff(): Argument #2 must be of type array, string given 143 144-- Iteration 22 --array_diff(): Argument #2 must be of type array, string given 145 146-- Iteration 23 --array_diff(): Argument #2 must be of type array, classA given 147 148-- Iteration 24 --array_diff(): Argument #2 must be of type array, null given 149 150-- Iteration 25 --array_diff(): Argument #2 must be of type array, null given 151 152-- Iteration 26 --array_diff(): Argument #2 must be of type array, resource given 153Done 154