#50688 [Com]: Warning When Handling Exception in a usort Callback Function
From: federico dot lebron at gmail dot com Date: Fri, 08 Jan 2010 01:51:56 +0000 Subject: #50688 [Com]: Warning When Handling Exception in a usort Callback Function References: 1 Groups: php.bugs Request: Send a blank email to php-bugs+get-146425@lists.php.net to get a copy of this message
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
Thread (20 messages)
- #50688 [Opn->Ver]: Warning When Handling Exception in a usort Callback Function
- #50688 [Com]: Warning When Handling Exception in a usort Callback Function
- #50688 [Ver->Asn]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Asn]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Com]: Using exceptions inside usort() callback function causes a warning
- Bug #50688 [Asn->Csd]: Using exceptions inside usort() callback function causes a warning
| « previous | php.bugs (#146425) | next » |
|---|