ID: 29049
Updated by: [EMAIL PROTECTED]
Reported By: bugs dot php dot net at chsc dot dk
-Status: Open
+Status: Verified
Bug Type: Arrays related
-Operating System: Linux
+Operating System: *
-PHP Version: 4.3.7
+PHP Version: 4CVS, 5CVS
New Comment:
There isn't any checking done in any of the u*sort() functions for the
callback being valid. (zend_is_callable() should be used?)
This might be intentional, since the check would slow these functions
down a bit..?
Previous Comments:
------------------------------------------------------------------------
[2004-07-07 15:02:08] bugs dot php dot net at chsc dot dk
Description:
------------
When the second argument to usort() is not a valid callback, no error
is triggered, and the return value is true.
This makes debugging tricky.
When invoked with an invalid callback, usort() for some reason
rearranges the values in the array anyway.
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
$array = array(1, 7, 3, 2);
var_dump(usort($array, 'not a function name'));
var_dump($array);
var_dump(usort($array, 9999));
var_dump($array);
var_dump(usort($array, array('foo', 'bar')));
var_dump($array);
?>
Expected result:
----------------
The output should be three error messages, three times "bool(false)"
and three times the original array.
Actual result:
--------------
bool(true)
array(4) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(7)
[3]=>
int(1)
}
bool(true)
array(4) {
[0]=>
int(1)
[1]=>
int(7)
[2]=>
int(3)
[3]=>
int(2)
}
bool(true)
array(4) {
[0]=>
int(2)
[1]=>
int(3)
[2]=>
int(7)
[3]=>
int(1)
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29049&edit=1