From:             jcampbell at remindermedia dot com
Operating system: Fedora Core 12
PHP version:      5.3.1
PHP Bug Type:     Arrays related
Bug description:  Warning When Handling Exception in a usort Callback Function

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 bug report at http://bugs.php.net/?id=50688&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50688&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50688&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50688&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50688&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50688&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50688&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50688&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50688&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50688&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50688&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50688&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50688&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50688&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50688&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50688&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50688&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50688&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50688&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50688&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50688&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50688&r=mysqlcfg

Reply via email to