Bug #66087 [Com]: set_error_handler returns handler that does not match the mask

From: Date: Sat, 16 Nov 2013 12:28:01 +0000
Subject: Bug #66087 [Com]: set_error_handler returns handler that does not match the mask
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182784@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66087&edit=1 ID: 66087 Comment by: ukrtelecom at gmail dot com Reported by: ukrtelecom at gmail dot com Summary: set_error_handler returns handler that does not match the mask Status: Not a bug Type: Bug Package: *General Issues Operating System: Ubuntu 12.04 x64 PHP Version: 5.4Git-2013-11-13 (Git) Block user comment: N Private report: N New Comment: That's it. We are implementing the stack using closures, and not sure what to do with callable response of the setter. A non-null result clearly states that some other lib set it's own handler and relays on iit.We feel it is not fare to throw it away, yet we have no idea how to use it. Thanks for the link tho. It is the feature we really need. Previous Comments: ------------------------------------------------------------------------ [2013-11-15 19:30:32] requinix@php.net There's actually a request for multiple error handlers already, though a bit old. https://bugs.php.net/bug.php?id=54548 On the bright side it's not too hard to implement your own "add_error_handler"-type function using a class: a method to add an error handler to an internally-managed stack, and a method that is the real error handler that goes through the stack calling handlers with matching masks until one succeeds (and if none do returns false so PHP's default handler takes over). ------------------------------------------------------------------------ [2013-11-15 17:34:55] ukrtelecom at gmail dot com Thanks Damian, I see what you mean, and it turned to even worse behaviour: in my scenario the handler I carefully defined for E_NOTICE errors will never be called. set_error_handler(function(){echo 1;}, E_NOTICE); set_error_handler(function(){echo 2;}, E_WARNING); echo $someUndefinedVar; results with ugly "Notice: Undefined variable: someUndefinedVar" instead of beautiful "1". I respect that my expectation to fire my handlers are too high, and it is not a bug. Could we classify it as a feature request then? You see, having a returned value from set_error_handler() I have no information about what errors it was handling before, which make it useless. What realistically you can do with previous handler with current implementation? ------------------------------------------------------------------------ [2013-11-13 18:45:04] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php set_error_handler() only installs one error handler. The mask doesn't mean "install this handler as the handler for this mask" but rather "install this handler as the one custom error handler but only call it for this mask". The other bug is about how previous error handlers are saved in a stack and can be recalled later but that the error mask is not treated the same way. A different issue; if you restore_error_handler()d after your code then the first handler (also $cb so you wouldn't notice the difference) would be restored but the mask would remain unchanged at E_WARNING. ------------------------------------------------------------------------ [2013-11-13 10:35:09] ukrtelecom at gmail dot com Description: ------------ set_error_handler returns the previously defined error handler for any mask. It must be related to https://bugs.php.net/bug.php?id=63206 Test script: --------------- <?php $cb = function ($errno, $errstr, $errfile, $errline, $errcontext){return false;}; var_dump(set_error_handler($cb, E_NOTICE)); var_dump(set_error_handler($cb, E_WARNING)); Expected result: ---------------- NULL NULL Actual result: -------------- NULL object(Closure)#1 (1) { ["parameter"]=> array(5) { ["$errno"]=> string(10) "<required>" ["$errstr"]=> string(10) "<required>" ["$errfile"]=> string(10) "<required>" ["$errline"]=> string(10) "<required>" ["$errcontext"]=> string(10) "<required>" } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66087&edit=1

« previous php.bugs (#182784) next »