1--TEST--
2Test array_udiff_assoc() function : usage variation - incorrect comparison functions
3--FILE--
4<?php
5/* Prototype  : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func)
6 * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function.
7 * Source code: ext/standard/array.c
8 * Alias to functions:
9 */
10
11
12echo "*** Testing array_udiff_assoc() : usage variation - differing comparison functions***\n";
13
14$arr1 = array(1);
15$arr2 = array(1,2);
16
17echo "\n-- comparison function with an incorrect return value --\n";
18function incorrect_return_value ($val1, $val2) {
19  return array(1);
20}
21var_dump(array_udiff_assoc($arr1, $arr2, 'incorrect_return_value'));
22
23echo "\n-- comparison function taking too many parameters --\n";
24function too_many_parameters ($val1, $val2, $val3) {
25  return 1;
26}
27try {
28	var_dump(array_udiff_assoc($arr1, $arr2, 'too_many_parameters'));
29} catch (Throwable $e) {
30	echo "Exception: " . $e->getMessage() . "\n";
31}
32
33echo "\n-- comparison function taking too few parameters --\n";
34function too_few_parameters ($val1) {
35  return 1;
36}
37var_dump(array_udiff_assoc($arr1, $arr2, 'too_few_parameters'));
38
39?>
40===DONE===
41--EXPECTF--
42*** Testing array_udiff_assoc() : usage variation - differing comparison functions***
43
44-- comparison function with an incorrect return value --
45array(1) {
46  [0]=>
47  int(1)
48}
49
50-- comparison function taking too many parameters --
51Exception: Too few arguments to function too_many_parameters(), 2 passed and exactly 3 expected
52
53-- comparison function taking too few parameters --
54array(1) {
55  [0]=>
56  int(1)
57}
58===DONE===
59