Annotation of embedaddon/php/ext/standard/tests/array/array_filter_error.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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:
10: echo "*** Testing array_filter() : error conditions ***\n";
11:
12: // zero arguments
13: echo "-- Testing array_filter() function with Zero arguments --";
14: var_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: */
23: function odd($input)
24: {
25: return ($input % 2 != 0);
26: }
27: $extra_arg = 10;
28:
29: // with one more than the expected number of arguments
30: echo "-- Testing array_filter() function with more than expected no. of arguments --";
31: var_dump( array_filter($input, "odd", $extra_arg) );
32:
33: // with incorrect callback function
34: echo "-- Testing array_filter() function with incorrect callback --";
35: var_dump( array_filter($input, "even") );
36:
37: echo "Done"
38: ?>
39: --EXPECTF--
40: *** Testing array_filter() : error conditions ***
41: -- Testing array_filter() function with Zero arguments --
42: Warning: array_filter() expects at least 1 parameter, 0 given in %s on line %d
43: NULL
44: -- Testing array_filter() function with more than expected no. of arguments --
45: Warning: array_filter() expects at most 2 parameters, 3 given in %s on line %d
46: NULL
47: -- Testing array_filter() function with incorrect callback --
48: Warning: array_filter() expects parameter 2 to be a valid callback, function 'even' not found or invalid function name in %s on line %d
49: NULL
50: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>