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