1--TEST--
2Test ksort() function : error conditions
3--FILE--
4<?php
5/* Prototype  : bool ksort(array &array_arg [, int sort_flags])
6 * Description: Sort an array by key, maintaining key to data correlation
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Testing ksort() function with all possible error conditions
12*/
13
14echo "*** Testing ksort() : error conditions ***\n";
15
16// Zero arguments
17echo "\n-- Testing ksort() function with Zero arguments --\n";
18var_dump( ksort() );
19
20//Test ksort with more than the expected number of arguments
21echo "\n-- Testing ksort() function with more than expected no. of arguments --\n";
22$array_arg = array(1 => 1, 2 => 2);
23$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC);
24$extra_arg = 10;
25
26// loop through $flag_value array and call krsort with all possible sort flag values
27foreach($flag_value as $key => $flag){
28  echo "\n- Sort flag = $key -\n";
29  $temp_array = $array_arg;
30  var_dump( ksort($temp_array,$flag, $extra_arg) );
31  var_dump( $temp_array);
32}
33
34echo "Done";
35?>
36--EXPECTF--
37*** Testing ksort() : error conditions ***
38
39-- Testing ksort() function with Zero arguments --
40
41Warning: ksort() expects at least 1 parameter, 0 given in %s on line %d
42bool(false)
43
44-- Testing ksort() function with more than expected no. of arguments --
45
46- Sort flag = SORT_REGULAR -
47
48Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d
49bool(false)
50array(2) {
51  [1]=>
52  int(1)
53  [2]=>
54  int(2)
55}
56
57- Sort flag = SORT_STRING -
58
59Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d
60bool(false)
61array(2) {
62  [1]=>
63  int(1)
64  [2]=>
65  int(2)
66}
67
68- Sort flag = SORT_NUMERIC -
69
70Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d
71bool(false)
72array(2) {
73  [1]=>
74  int(1)
75  [2]=>
76  int(2)
77}
78Done
79