ID: 50688 Updated by: j...@php.net Reported By: jcampbell at remindermedia dot com -Status: Open +Status: Verified Bug Type: Arrays related Operating System: Fedora Core 12 -PHP Version: 5.3.1 +PHP Version: 5.*, 6
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