ID:               50688
 Updated by:       j...@php.net
 Reported By:      jcampbell at remindermedia dot com
-Status:           Verified
+Status:           Assigned
 Bug Type:         Arrays related
 Operating System: Fedora Core 12
 PHP Version:      5.*, 6
-Assigned To:      
+Assigned To:      stas
 New Comment:

This was caused by the fix for bug #50006 (there weren't such checks
before :)

Stas, can you check this out? Didn't expect anyone to use exceptions,
did you? :D


Previous Comments:
------------------------------------------------------------------------

[2010-01-08 01:51:56] federico dot lebron at gmail dot com

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.

------------------------------------------------------------------------

[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

Reply via email to