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