1--TEST--
2Test array_filter() function : error conditions
3--FILE--
4<?php
5/* Prototype  : array array_filter(array $input [, callback $callback])
6 * Description: Filters elements from the array via the callback.
7 * Source code: ext/standard/array.c
8*/
9
10echo "*** Testing array_filter() : error conditions ***\n";
11
12// zero arguments
13echo "-- Testing array_filter() function with Zero arguments --";
14var_dump( array_filter() );
15
16$input = array(0, 1, 2, 3, 5);
17/*  callback function
18 *  Prototype : bool odd(array $input)
19 *  Parameters : $input - array for which each elements should be checked into the function
20 *  Return Type : bool - true if element is odd and returns false otherwise
21 *  Description : Function takes array as input and checks for its each elements.
22*/
23function odd($input)
24{
25  return ($input % 2 != 0);
26}
27$extra_arg = 10;
28
29// with one more than the expected number of arguments
30echo "-- Testing array_filter() function with more than expected no. of arguments --";
31var_dump( array_filter($input, "odd", $extra_arg) );
32
33// with incorrect callback function
34echo "-- Testing array_filter() function with incorrect callback --";
35var_dump( array_filter($input, "even") );
36
37echo "Done"
38?>
39--EXPECTF--
40*** Testing array_filter() : error conditions ***
41-- Testing array_filter() function with Zero arguments --
42Warning: array_filter() expects at least 1 parameter, 0 given in %s on line %d
43NULL
44-- Testing array_filter() function with more than expected no. of arguments --
45Warning: array_filter() expects at most 2 parameters, 3 given in %s on line %d
46NULL
47-- Testing array_filter() function with incorrect callback --
48Warning: array_filter() expects parameter 2 to be a valid callback, function 'even' not found or invalid function name in %s on line %d
49NULL
50Done
51