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