1--TEST-- 2Test array_map() function : usage variations - anonymous callback function 3--FILE-- 4<?php 5/* 6 * Test array_map() by passing anonymous callback function with following variations 7 */ 8 9echo "*** Testing array_map() : anonymous callback function ***\n"; 10 11$array1 = array(1, 2, 3); 12$array2 = array(3, 4, 5); 13 14echo "-- anonymous function with all parameters and body --\n"; 15var_dump( array_map( function($a, $b) { return array($a, $b); }, $array1, $array2)); 16 17echo "-- anonymous function with two parameters and passing one array --\n"; 18try { 19 var_dump( array_map( function($a, $b) { return array($a, $b); }, $array1)); 20} catch (Throwable $e) { 21 echo "Exception: " . $e->getMessage() . "\n"; 22} 23 24echo "-- anonymous function with NULL parameter --\n"; 25var_dump( array_map( function() { return NULL; }, $array1)); 26 27echo "-- anonymous function with NULL body --\n"; 28var_dump( array_map( function($a) { }, $array1)); 29 30echo "-- passing NULL as 'array1' --\n"; 31try { 32 var_dump( array_map( function($a) { return array($a); }, NULL)); 33} catch (TypeError $e) { 34 echo $e->getMessage(), "\n"; 35} 36 37echo "Done"; 38?> 39--EXPECT-- 40*** Testing array_map() : anonymous callback function *** 41-- anonymous function with all parameters and body -- 42array(3) { 43 [0]=> 44 array(2) { 45 [0]=> 46 int(1) 47 [1]=> 48 int(3) 49 } 50 [1]=> 51 array(2) { 52 [0]=> 53 int(2) 54 [1]=> 55 int(4) 56 } 57 [2]=> 58 array(2) { 59 [0]=> 60 int(3) 61 [1]=> 62 int(5) 63 } 64} 65-- anonymous function with two parameters and passing one array -- 66Exception: Too few arguments to function {closure}(), 1 passed and exactly 2 expected 67-- anonymous function with NULL parameter -- 68array(3) { 69 [0]=> 70 NULL 71 [1]=> 72 NULL 73 [2]=> 74 NULL 75} 76-- anonymous function with NULL body -- 77array(3) { 78 [0]=> 79 NULL 80 [1]=> 81 NULL 82 [2]=> 83 NULL 84} 85-- passing NULL as 'array1' -- 86array_map(): Argument #2 ($array) must be of type array, null given 87Done 88