1--TEST-- 2Test array_map() function : usage variations - null value for 'callback' argument 3--FILE-- 4<?php 5/* 6 * Test array_map() by passing null values for $callback argument and testing whether shortest 7 * array will be extended with empty elements 8 */ 9 10echo "*** Testing array_map() : null value for 'callback' argument ***\n"; 11 12// arrays to be passed as arguments 13$arr1 = array(1, 2); 14$arr2 = array("one", "two"); 15$arr3 = array(1.1, 2.2); 16 17// get an unset variable 18$unset_var = 10; 19unset ($unset_var); 20 21/* calling array_map() with null callback */ 22 23echo "-- with null --\n"; 24var_dump( array_map(null, $arr1, $arr2, $arr3) ); 25var_dump( array_map(NULL, $arr1, $arr2, $arr3) ); 26 27echo "-- with unset variable --\n"; 28var_dump( array_map(@$unset_var, $arr1, $arr2, $arr3) ); 29 30echo "-- with undefined variable --\n"; 31var_dump( array_map(@$undefined_var, $arr1) ); 32 33echo "-- with empty string --\n"; 34try { 35 var_dump( array_map("", $arr1, $arr2) ); 36} catch (TypeError $e) { 37 echo $e->getMessage(), "\n"; 38} 39 40echo "-- with empty array --\n"; 41try { 42 var_dump( array_map(array(), $arr1, $arr2) ); 43} catch (TypeError $e) { 44 echo $e->getMessage(), "\n"; 45} 46 47echo "Done"; 48?> 49--EXPECT-- 50*** Testing array_map() : null value for 'callback' argument *** 51-- with null -- 52array(2) { 53 [0]=> 54 array(3) { 55 [0]=> 56 int(1) 57 [1]=> 58 string(3) "one" 59 [2]=> 60 float(1.1) 61 } 62 [1]=> 63 array(3) { 64 [0]=> 65 int(2) 66 [1]=> 67 string(3) "two" 68 [2]=> 69 float(2.2) 70 } 71} 72array(2) { 73 [0]=> 74 array(3) { 75 [0]=> 76 int(1) 77 [1]=> 78 string(3) "one" 79 [2]=> 80 float(1.1) 81 } 82 [1]=> 83 array(3) { 84 [0]=> 85 int(2) 86 [1]=> 87 string(3) "two" 88 [2]=> 89 float(2.2) 90 } 91} 92-- with unset variable -- 93array(2) { 94 [0]=> 95 array(3) { 96 [0]=> 97 int(1) 98 [1]=> 99 string(3) "one" 100 [2]=> 101 float(1.1) 102 } 103 [1]=> 104 array(3) { 105 [0]=> 106 int(2) 107 [1]=> 108 string(3) "two" 109 [2]=> 110 float(2.2) 111 } 112} 113-- with undefined variable -- 114array(2) { 115 [0]=> 116 int(1) 117 [1]=> 118 int(2) 119} 120-- with empty string -- 121array_map(): Argument #1 ($callback) must be a valid callback or null, function "" not found or invalid function name 122-- with empty array -- 123array_map(): Argument #1 ($callback) must be a valid callback or null, array must have exactly two members 124Done 125