#29049 [Asn->Csd]: usort() does not trigger an error when callback does not exist
| From: | iliaa@php.net | Date: | Thu, 08 Jul 2004 17:07:34 +0000 |
| Subject: | #29049 [Asn->Csd]: usort() does not trigger an error when callback does not exist | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-61931@lists.php.net to get a copy of this message | ||
ID: 29049
Updated by: iliaa@php.net
Reported By: bugs dot php dot net at chsc dot dk
-Status: Assigned
+Status: Closed
Bug Type: Arrays related
Operating System: *
PHP Version: 4CVS, 5CVS
Assigned To: iliaa
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2004-07-08 11:29:14] sniper@php.net
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..?
------------------------------------------------------------------------
[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