Edit report at http://bugs.php.net/bug.php?id=50688&edit=1
ID: 50688
Comment by: philipwhiuk at hotmail dot com
Reported by: jcampbell at remindermedia dot com
Summary: Using exceptions inside usort() callback function
causes a warning
Status: Assigned
Type: Bug
Package: Arrays related
Operating System: Fedora Core 12
PHP Version: 5.*, 6
Assigned To: stas
Block user comment: N
New Comment:
I notice this is still affecting PHP 5.3.3 (Windows/Apache install).
Is this likely to be fixed soon - is it a question of developer time and
priority
or is it too difficult to fix?
It's quite irritating - I realise that the obvious solution is to avoid
throwing
the exception (ha-ha) but it's a useful function and exceptions are...
inevitable.
Previous Comments:
------------------------------------------------------------------------
[2010-05-31 17:24:05] ajrattink at correct dot net
I printed a debug line from my usort callback. It called
debug_backtrace() to print the line and sourcefile in the debuglog. And
therefor triggered the error. Even more, it did not sort.
Maybe the phpmanual should state that usort() callbacks are not allowed
to write loglines. I also think that usort() callbacks that DO change
the array are perfectly legal, as long as they don't change the sort.
Maybe your sorter code needs stackoverflow protection or whatever, but
calling certain code 'invalid', because it causes your code to SEGV is a
stupid way to solve a bug.
------------------------------------------------------------------------
[2010-04-01 02:12:52] [email protected]
The reason seems to be that when making exception backtrace,
debug_backtrace_get_args() uses SEPARATE_ZVAL_TO_MAKE_IS_REF() on
arguments, which makes it look as if the argument was indeed modified
(which usort is designed to protect against, since cmp callback is not
supposed to modify the arguments)
------------------------------------------------------------------------
[2010-03-05 17:41:30] bernie at dcbl dot ca
affects gentoo builds after > 5.2.10 (5.2.11, 5.2.11-r1, and 5.2.12)
------------------------------------------------------------------------
[2010-01-20 10:22:01] [email protected]
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
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=50688
--
Edit this bug report at http://bugs.php.net/bug.php?id=50688&edit=1