1--TEST-- 2Test usort() function : error conditions - Pass unknown 'cmp_function' 3--FILE-- 4<?php 5/* Prototype : bool usort(array $array_arg, string $cmp_function) 6 * Description: Sort an array by values using a user-defined comparison function 7 * Source code: ext/standard/array.c 8 */ 9 10/* 11 * Pass an unknown comparison function to usort() to test behaviour. 12 * Pass incorrect number of arguments and an unknown function to test which error 13 * is generated. 14 */ 15 16echo "*** Testing usort() : error conditions ***\n"; 17 18function cmp($value1, $value2) 19{ 20 if($value1 == $value2) { 21 return 0; 22 } 23 else if($value1 > $value2) { 24 return 1; 25 } 26 else { 27 return -1; 28 } 29} 30 31// Initialize 'array_arg' 32$array_arg = array(0 => 1, 1 => 10, 2 => 'string', 3 => 3, 4 => 2, 5 => 100, 6 => 25); 33$extra_arg = 10; 34 35// With non existent comparison function 36echo "\n-- Testing usort() function with non-existent compare function --\n"; 37var_dump( usort($array_arg, 'non_existent') ); 38 39// With non existent comparison function and extra argument 40echo "\n-- Testing usort() function with non-existent compare function and extra argument --\n"; 41var_dump( usort($array_arg, 'non_existent', $extra_arg) ); 42?> 43===DONE=== 44--EXPECTF-- 45*** Testing usort() : error conditions *** 46 47-- Testing usort() function with non-existent compare function -- 48 49Warning: usort() expects parameter 2 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d 50NULL 51 52-- Testing usort() function with non-existent compare function and extra argument -- 53 54Warning: usort() expects exactly 2 parameters, 3 given in %s on line %d 55NULL 56===DONE===