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