1--TEST--
2Test array_map() function : error conditions
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
10echo "*** Testing array_map() : error conditions ***\n";
11
12// Zero arguments
13echo "\n-- Testing array_map() function with Zero arguments --\n";
14var_dump( array_map() );
15
16// Testing array_map with one less than the expected number of arguments
17echo "\n-- Testing array_map() function with one less than expected no. of arguments --\n";
18function callback1() {
19  return 1;
20}
21try {
22	var_dump( array_map('callback1') );
23} catch (Throwable $e) {
24	echo "Exception: " . $e->getMessage() . "\n";
25}
26
27echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n";
28$arr1 = array(1, 2);
29function callback2($p, $q) {
30  return $p * $q;
31}
32try {
33	var_dump( array_map('callback2', $arr1) );
34} catch (Throwable $e) {
35	echo "Exception: " . $e->getMessage() . "\n";
36}
37
38echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n";
39$arr2 = array(3, 4);
40$arr3 = array(5, 6);
41var_dump( array_map('callback2', $arr1, $arr2, $arr3) );
42
43echo "Done";
44?>
45--EXPECTF--
46*** Testing array_map() : error conditions ***
47
48-- Testing array_map() function with Zero arguments --
49
50Warning: array_map() expects at least 2 parameters, 0 given in %s on line %d%d
51NULL
52
53-- Testing array_map() function with one less than expected no. of arguments --
54
55Warning: array_map() expects at least 2 parameters, 1 given in %s on line %d%d
56NULL
57
58-- Testing array_map() function with less no. of arrays than callback function arguments --
59Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected
60
61-- Testing array_map() function with more no. of arrays than callback function arguments --
62array(2) {
63  [0]=>
64  int(3)
65  [1]=>
66  int(8)
67}
68Done
69