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( create_function('$a, $b', 'return array($a, $b);'), $array1, $array2));
21
22echo "-- anonymous function with two parameters and passing one array --\n";
23var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1));
24
25echo "-- anonymous function with NULL parameter --\n";
26var_dump( array_map( create_function(NULL, 'return NULL;'), $array1));
27
28echo "-- anonymous function with NULL body --\n";
29var_dump( array_map( create_function('$a', NULL), $array1));
30
31echo "-- passing NULL as 'arr1' --\n";
32var_dump( array_map( create_function('$a', 'return array($a);'), NULL));
33
34echo "Done";
35?>
36--EXPECTF--
37*** Testing array_map() : anonymous callback function ***
38-- anonymous function with all parameters and body --
39array(3) {
40  [0]=>
41  array(2) {
42    [0]=>
43    int(1)
44    [1]=>
45    int(3)
46  }
47  [1]=>
48  array(2) {
49    [0]=>
50    int(2)
51    [1]=>
52    int(4)
53  }
54  [2]=>
55  array(2) {
56    [0]=>
57    int(3)
58    [1]=>
59    int(5)
60  }
61}
62-- anonymous function with two parameters and passing one array --
63
64Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
65
66Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
67
68Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
69
70Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
71
72Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d
73
74Notice: Undefined variable: b in %s(20) : runtime-created function on line %d
75array(3) {
76  [0]=>
77  array(2) {
78    [0]=>
79    int(1)
80    [1]=>
81    NULL
82  }
83  [1]=>
84  array(2) {
85    [0]=>
86    int(2)
87    [1]=>
88    NULL
89  }
90  [2]=>
91  array(2) {
92    [0]=>
93    int(3)
94    [1]=>
95    NULL
96  }
97}
98-- anonymous function with NULL parameter --
99array(3) {
100  [0]=>
101  NULL
102  [1]=>
103  NULL
104  [2]=>
105  NULL
106}
107-- anonymous function with NULL body --
108array(3) {
109  [0]=>
110  NULL
111  [1]=>
112  NULL
113  [2]=>
114  NULL
115}
116-- passing NULL as 'arr1' --
117
118Warning: array_map(): Argument #2 should be an array in %s on line %d
119NULL
120Done
121