2 Test ksort() function : usage variations - unexpected values for 'sort_flags' argument
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
11 * Testing ksort() by providing different unexpected values for flag argument
14 echo "*** Testing ksort() : usage variations ***\n";
16 //get an unset variable
21 $fp = fopen(__FILE__, "r");
23 // an array for checking unexpected behavior
24 $unsorted_values = array(10 => 10, 2 => 2, 45 => 45);
26 //array of unexpected values to iterate over
27 $unexpected_values = array (
58 /*16*/ new stdclass(),
61 /*17*/ @undefined_var,
71 // loop though each element of the array and check the working of ksort()
72 // when 'sort_flags' arugment is supplied with different values
73 echo "\n-- Testing ksort() by supplying different unexpected values for 'sort_flags' argument --\n";
76 for($index = 0; $index < count($unexpected_values); $index ++) {
77 echo "-- Iteration $counter --\n";
78 $value = $unexpected_values [$index];
79 $temp_array = $unsorted_values;
80 var_dump( ksort($temp_array, $value) );
81 var_dump($temp_array);
88 *** Testing ksort() : usage variations ***
90 -- Testing ksort() by supplying different unexpected values for 'sort_flags' argument --
213 Warning: ksort() expects parameter 2 to be long, string given in %s on line %d
225 Warning: ksort() expects parameter 2 to be long, string given in %s on line %d
237 Warning: ksort() expects parameter 2 to be long, string given in %s on line %d
249 Warning: ksort() expects parameter 2 to be long, string given in %s on line %d
261 Warning: ksort() expects parameter 2 to be long, object given in %s on line %d
273 Warning: ksort() expects parameter 2 to be long, string given in %s on line %d
285 Warning: ksort() expects parameter 2 to be long, string given in %s on line %d
297 Warning: ksort() expects parameter 2 to be long, resource given in %s on line %d