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