1--TEST--
2Test array_map() function : error conditions
3--FILE--
4<?php
5echo "*** Testing array_map() : error conditions ***\n";
6
7// Testing array_map with one less than the expected number of arguments
8echo "\n-- Testing array_map() function with one less than expected no. of arguments --\n";
9function callback1() {
10  return 1;
11}
12try {
13    var_dump( array_map('callback1') );
14} catch (Throwable $e) {
15    echo "Exception: " . $e->getMessage() . "\n";
16}
17
18echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n";
19$arr1 = array(1, 2);
20function callback2($p, $q) {
21  return $p * $q;
22}
23try {
24    var_dump( array_map('callback2', $arr1) );
25} catch (Throwable $e) {
26    echo "Exception: " . $e->getMessage() . "\n";
27}
28
29echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n";
30$arr2 = array(3, 4);
31$arr3 = array(5, 6);
32var_dump( array_map('callback2', $arr1, $arr2, $arr3) );
33
34echo "Done";
35?>
36--EXPECT--
37*** Testing array_map() : error conditions ***
38
39-- Testing array_map() function with one less than expected no. of arguments --
40Exception: array_map() expects at least 2 arguments, 1 given
41
42-- Testing array_map() function with less no. of arrays than callback function arguments --
43Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected
44
45-- Testing array_map() function with more no. of arrays than callback function arguments --
46array(2) {
47  [0]=>
48  int(3)
49  [1]=>
50  int(8)
51}
52Done
53