1--TEST-- 2Test array_walk_recursive() function : usage variations - unexpected values for 'input' argument 3--FILE-- 4<?php 5/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) 6 * Description: Apply a user function to every member of an array 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * Passing different scalar/nonscalar values in place of 'input' argument 12*/ 13 14echo "*** Testing array_walk_recursive() : unexpected values for 'input' argument ***\n"; 15 16// callback function 17/* Prototype : callback(mixed $value, mixed $key) 18 * Parameters : $value - values given in input array 19 * $key - keys given in input array 20 * Description : Function prints each element of an array with key 21 */ 22function callback($value, $key) 23{ 24 echo "key : "; 25 var_dump($key); 26 echo "value : "; 27 var_dump($value); 28} 29 30// extra parameter passed to array_walk_recursive() 31$user_data = 10; 32 33// get an unset variable 34$unset_var = 10; 35unset ($unset_var); 36 37// get resource variable 38$fp = fopen(__FILE__, 'r'); 39 40// different scalar/nonscalar values to be used in place of an 'input' argument 41$input_values = array( 42 43 // int data 44/* 1*/ 0, 45 1, 46 12345, 47 -2345, 48 49 // float data 50/* 5*/ 10.5, 51 -10.5, 52 10.1234567e8, 53 10.7654321E-8, 54 .5, 55 56 // null data 57/* 10*/ NULL, 58 null, 59 60 // boolean data 61/* 12*/ true, 62 false, 63 TRUE, 64 FALSE, 65 66 // empty data 67/* 16*/ "", 68 '', 69 70 // string data 71/* 18*/ "string", 72 'string', 73 74 // resource data 75 $fp, 76 77 // undefined data 78 @$undefined_var, 79 80 // unset data 81/* 22*/ @$unset_var, 82); 83 84 85for($count = 0; $count < count($input_values); $count++) { 86 echo "-- Iteration ".($count + 1)." --\n"; 87 var_dump( array_walk_recursive($input_values[$count], "callback") ); 88 var_dump( array_walk_recursive($input_values[$count], "callback", $user_data) ); 89} 90 91fclose($fp); 92echo "Done" 93?> 94--EXPECTF-- 95*** Testing array_walk_recursive() : unexpected values for 'input' argument *** 96-- Iteration 1 -- 97 98Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 99NULL 100 101Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 102NULL 103-- Iteration 2 -- 104 105Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 106NULL 107 108Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 109NULL 110-- Iteration 3 -- 111 112Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 113NULL 114 115Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 116NULL 117-- Iteration 4 -- 118 119Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 120NULL 121 122Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d 123NULL 124-- Iteration 5 -- 125 126Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 127NULL 128 129Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 130NULL 131-- Iteration 6 -- 132 133Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 134NULL 135 136Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 137NULL 138-- Iteration 7 -- 139 140Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 141NULL 142 143Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 144NULL 145-- Iteration 8 -- 146 147Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 148NULL 149 150Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 151NULL 152-- Iteration 9 -- 153 154Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 155NULL 156 157Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d 158NULL 159-- Iteration 10 -- 160 161Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 162NULL 163 164Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 165NULL 166-- Iteration 11 -- 167 168Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 169NULL 170 171Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 172NULL 173-- Iteration 12 -- 174 175Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 176NULL 177 178Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 179NULL 180-- Iteration 13 -- 181 182Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 183NULL 184 185Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 186NULL 187-- Iteration 14 -- 188 189Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 190NULL 191 192Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 193NULL 194-- Iteration 15 -- 195 196Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 197NULL 198 199Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d 200NULL 201-- Iteration 16 -- 202 203Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 204NULL 205 206Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 207NULL 208-- Iteration 17 -- 209 210Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 211NULL 212 213Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 214NULL 215-- Iteration 18 -- 216 217Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 218NULL 219 220Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 221NULL 222-- Iteration 19 -- 223 224Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 225NULL 226 227Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d 228NULL 229-- Iteration 20 -- 230 231Warning: array_walk_recursive() expects parameter 1 to be array, resource given in %s on line %d 232NULL 233 234Warning: array_walk_recursive() expects parameter 1 to be array, resource given in %s on line %d 235NULL 236-- Iteration 21 -- 237 238Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 239NULL 240 241Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 242NULL 243-- Iteration 22 -- 244 245Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 246NULL 247 248Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d 249NULL 250Done 251