1--TEST-- 2Test array_map() function : usage variations - unexpected values for 'callback' 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 different scalar/nonscalar values in place of $callback 12 */ 13 14echo "*** Testing array_map() : unexpected values for 'callback' argument ***\n"; 15 16$arr1 = array(1, 2, 3); 17 18// get a class 19class classA 20{ 21 public function __toString() { 22 return "Class A object"; 23 } 24} 25 26// get a resource variable 27$fp = fopen(__FILE__, "r"); 28 29// unexpected values to be passed to $input argument 30$unexpected_callbacks = array( 31 32 // int data 33/*1*/ 0, 34 1, 35 12345, 36 -2345, 37 38 // float data 39/*5*/ 10.5, 40 -10.5, 41 12.3456789000e10, 42 12.3456789000E-10, 43 .5, 44 45 // boolean data 46/*10*/ true, 47 false, 48 TRUE, 49 FALSE, 50 51 // empty data 52/*14*/ "", 53 '', 54 55 // array data 56/*16*/ array(), 57 array(1, 2), 58 array(1, array(2)), 59 60 // object data 61/*19*/ new classA(), 62 63 // resource variable 64/*20*/ $fp 65); 66 67// loop through each element of $inputs to check the behavior of array_map 68for($count = 0; $count < count($unexpected_callbacks); $count++) { 69 echo "\n-- Iteration ".($count + 1)." --"; 70 var_dump( array_map($unexpected_callbacks[$count], $arr1)); 71}; 72 73fclose($fp); 74echo "Done"; 75?> 76--EXPECTF-- 77*** Testing array_map() : unexpected values for 'callback' argument *** 78 79-- Iteration 1 -- 80Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 81NULL 82 83-- Iteration 2 -- 84Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 85NULL 86 87-- Iteration 3 -- 88Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 89NULL 90 91-- Iteration 4 -- 92Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 93NULL 94 95-- Iteration 5 -- 96Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 97NULL 98 99-- Iteration 6 -- 100Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 101NULL 102 103-- Iteration 7 -- 104Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 105NULL 106 107-- Iteration 8 -- 108Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 109NULL 110 111-- Iteration 9 -- 112Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 113NULL 114 115-- Iteration 10 -- 116Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 117NULL 118 119-- Iteration 11 -- 120Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 121NULL 122 123-- Iteration 12 -- 124Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 125NULL 126 127-- Iteration 13 -- 128Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 129NULL 130 131-- Iteration 14 -- 132Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d 133NULL 134 135-- Iteration 15 -- 136Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d 137NULL 138 139-- Iteration 16 -- 140Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %s on line %d 141NULL 142 143-- Iteration 17 -- 144Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d 145NULL 146 147-- Iteration 18 -- 148Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d 149NULL 150 151-- Iteration 19 -- 152Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 153NULL 154 155-- Iteration 20 -- 156Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 157NULL 158Done 159