2 Test array_map() function : error conditions
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
10 echo "*** Testing array_map() : error conditions ***\n";
12 // Testing array_map with one less than the expected number of arguments
13 echo "\n-- Testing array_map() function with one less than expected no. of arguments --\n";
14 function callback1() {
18 var_dump( array_map('callback1') );
19 } catch (Throwable $e) {
20 echo "Exception: " . $e->getMessage() . "\n";
23 echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n";
25 function callback2($p, $q) {
29 var_dump( array_map('callback2', $arr1) );
30 } catch (Throwable $e) {
31 echo "Exception: " . $e->getMessage() . "\n";
34 echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n";
37 var_dump( array_map('callback2', $arr1, $arr2, $arr3) );
42 *** Testing array_map() : error conditions ***
44 -- Testing array_map() function with one less than expected no. of arguments --
45 Exception: array_map() expects at least 2 parameters, 1 given
47 -- Testing array_map() function with less no. of arrays than callback function arguments --
48 Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected
50 -- Testing array_map() function with more no. of arrays than callback function arguments --