1--TEST-- 2Test each() function : usage variations - Pass different data types as $arr arg 3--FILE-- 4<?php 5/* Prototype : array each(array $arr) 6 * Description: Return the currently pointed key..value pair in the passed array, 7 * and advance the pointer to the next element 8 * Source code: Zend/zend_builtin_functions.c 9 */ 10 11/* 12 * Pass different data types as $arr arg to each() to test behaviour 13 */ 14 15echo "*** Testing each() : usage variations ***\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 $arr 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 array(), 67 68 // string data 69/*19*/ "string", 70 'string', 71 $heredoc, 72 73 // object data 74/*22*/ new classA(), 75 76 // undefined data 77/*23*/ @$undefined_var, 78 79 // unset data 80/*24*/ @$unset_var, 81 82 // resource variable 83/*25*/ $fp 84); 85 86// loop through each element of $inputs to check the behavior of each() 87$iterator = 1; 88foreach($inputs as $input) { 89 echo "\n-- Iteration $iterator --\n"; 90 var_dump( each($input) ); 91 $iterator++; 92}; 93 94fclose($fp); 95 96echo "Done"; 97?> 98--EXPECTF-- 99*** Testing each() : usage variations *** 100 101-- Iteration 1 -- 102 103Warning: Variable passed to each() is not an array or object in %s on line %d 104NULL 105 106-- Iteration 2 -- 107 108Warning: Variable passed to each() is not an array or object in %s on line %d 109NULL 110 111-- Iteration 3 -- 112 113Warning: Variable passed to each() is not an array or object in %s on line %d 114NULL 115 116-- Iteration 4 -- 117 118Warning: Variable passed to each() is not an array or object in %s on line %d 119NULL 120 121-- Iteration 5 -- 122 123Warning: Variable passed to each() is not an array or object in %s on line %d 124NULL 125 126-- Iteration 6 -- 127 128Warning: Variable passed to each() is not an array or object in %s on line %d 129NULL 130 131-- Iteration 7 -- 132 133Warning: Variable passed to each() is not an array or object in %s on line %d 134NULL 135 136-- Iteration 8 -- 137 138Warning: Variable passed to each() is not an array or object in %s on line %d 139NULL 140 141-- Iteration 9 -- 142 143Warning: Variable passed to each() is not an array or object in %s on line %d 144NULL 145 146-- Iteration 10 -- 147 148Warning: Variable passed to each() is not an array or object in %s on line %d 149NULL 150 151-- Iteration 11 -- 152 153Warning: Variable passed to each() is not an array or object in %s on line %d 154NULL 155 156-- Iteration 12 -- 157 158Warning: Variable passed to each() is not an array or object in %s on line %d 159NULL 160 161-- Iteration 13 -- 162 163Warning: Variable passed to each() is not an array or object in %s on line %d 164NULL 165 166-- Iteration 14 -- 167 168Warning: Variable passed to each() is not an array or object in %s on line %d 169NULL 170 171-- Iteration 15 -- 172 173Warning: Variable passed to each() is not an array or object in %s on line %d 174NULL 175 176-- Iteration 16 -- 177 178Warning: Variable passed to each() is not an array or object in %s on line %d 179NULL 180 181-- Iteration 17 -- 182 183Warning: Variable passed to each() is not an array or object in %s on line %d 184NULL 185 186-- Iteration 18 -- 187bool(false) 188 189-- Iteration 19 -- 190 191Warning: Variable passed to each() is not an array or object in %s on line %d 192NULL 193 194-- Iteration 20 -- 195 196Warning: Variable passed to each() is not an array or object in %s on line %d 197NULL 198 199-- Iteration 21 -- 200 201Warning: Variable passed to each() is not an array or object in %s on line %d 202NULL 203 204-- Iteration 22 -- 205bool(false) 206 207-- Iteration 23 -- 208 209Warning: Variable passed to each() is not an array or object in %s on line %d 210NULL 211 212-- Iteration 24 -- 213 214Warning: Variable passed to each() is not an array or object in %s on line %d 215NULL 216 217-- Iteration 25 -- 218 219Warning: Variable passed to each() is not an array or object in %s on line %d 220NULL 221Done 222