1--TEST--
2Test uasort() function : error conditions
3--FILE--
4<?php
5/* Prototype  : bool uasort(array $array_arg, string $cmp_function)
6 * Description: Sort an array with a user-defined comparison function and maintain index association
7 * Source code: ext/standard/array.c
8*/
9
10echo "*** Testing uasort() : error conditions ***\n";
11
12// comparison function
13/* Prototype : int cmp(mixed $value1, mixed $value2)
14 * Parameters : $value1 and $value2 - values to be compared
15 * Return value : 0 - if both values are same
16 *                1 - if value1 is greater than value2
17 *               -1 - if value1 is less than value2
18 * Description : compares value1 and value2
19 */
20function cmp($value1, $value2)
21{
22  if($value1 == $value2) {
23    return 0;
24  }
25  else if($value1 > $value2) {
26    return 1;
27  }
28  else {
29    return -1;
30  }
31}
32
33// Initialize 'array_arg'
34$array_arg = array(0 => 1, 1 => 10, 2 => 'string', 3 => 3, 4 => 2, 5 => 100, 6 => 25);
35
36// With zero arguments
37echo "-- Testing uasort() function with Zero argument --\n";
38var_dump( uasort() );
39
40// With one more than the expected number of arguments
41echo "-- Testing uasort() function with more than expected no. of arguments --\n";
42$extra_arg = 10;
43var_dump( uasort($array_arg, 'cmp', $extra_arg) );
44
45// With one less than the expected number of arguments
46echo "-- Testing uasort() function with less than expected no. of arguments --\n";
47var_dump( uasort($array_arg) );
48
49// With non existent comparison function
50echo "-- Testing uasort() function with non-existent compare function --\n";
51var_dump( uasort($array_arg, 'non_existent') );
52
53// With non existent comparison function and extra arguemnt
54echo "-- Testing uasort() function with non-existent compare function and extra argument --\n";
55var_dump( uasort($array_arg, 'non_existent', $extra_arg) );
56
57echo "Done"
58?>
59--EXPECTF--
60*** Testing uasort() : error conditions ***
61-- Testing uasort() function with Zero argument --
62
63Warning: uasort() expects exactly 2 parameters, 0 given in %s on line %d
64NULL
65-- Testing uasort() function with more than expected no. of arguments --
66
67Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d
68NULL
69-- Testing uasort() function with less than expected no. of arguments --
70
71Warning: uasort() expects exactly 2 parameters, 1 given in %s on line %d
72NULL
73-- Testing uasort() function with non-existent compare function --
74
75Warning: uasort() expects parameter 2 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d
76NULL
77-- Testing uasort() function with non-existent compare function and extra argument --
78
79Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d
80NULL
81Done
82