ID: 50688
Comment by: federico dot lebron at gmail dot com
Reported By: jcampbell at remindermedia dot com
Status: Verified
Bug Type: Arrays related
Operating System: Fedora Core 12
PHP Version: 5.*, 6
New Comment:
The problem seems to be that usort checks the amount of references
before and after the function call to see if the user-provided function
modified it, but inside the function call, debug_backtrace_get_args
adds
a reference to the passed variables to use in e.g. debug_backtrace's
"arg" element.
Previous Comments:
------------------------------------------------------------------------
[2010-01-07 19:42:30] jcampbell at remindermedia dot com
Description:
------------
If the callback function used by usort handles an exception using a
try/catch block, a warning is generated. The correct sorting is still
done. This happens even when the exception & handling doesn't involve
the variables.
The example below is the usort example from the manual with only the
try/catch block added. Reproducible in PHP 5.2.11 but not 5.2.9
Reproduce code:
---------------
<?php
function cmp($a, $b)
{
if ($a == $b) {
return 0;
}
try {
throw new Exception();
} catch (Exception $E) {
}
return ($a < $b) ? -1 : 1;
}
$a = array(3, 2, 5, 6, 1);
usort($a, "cmp");
Expected result:
----------------
No warning message.
Actual result:
--------------
PHP Warning: usort(): Array was modified by the user comparison
function in /home/jcampbell/usortExceptionWarning.php on line 19
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50688&edit=1