Edit report at https://bugs.php.net/bug.php?id=54033&edit=1
ID: 54033 Comment by: matthew dot bonner at gmail dot com Reported by: tyra3l at gmail dot com Summary: add get_error_handler and get_exception handler Status: Open Type: Feature/Change Request Package: Scripting Engine problem PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: For anyone else who finds the implementation of the error handling functions a bug, the following might help: function void_error_handler () {} function get_error_handler () { $error_handler = set_error_handler('void_error_handler'); restore_error_handler(); return $error_handler; } function restore_php_error_handler () { while (set_error_handler('void_error_handler') !== NULL) { restore_error_handler(); restore_error_handler(); } } This is what we have to resort to, stop not admitting this is a bug when it is! Previous Comments: ------------------------------------------------------------------------ [2012-08-25 14:23:29] matthew dot bonner at gmail dot com I would like to add that I'm aware PHP stacks up the error handlers, so calling restore_error_handler over and over will eventually restore the original error handler but this isn't possible unless you do something like: restore_error_handler(); restore_error_handler(); restore_error_handler(); restore_error_handler(); restore_error_handler(); restore_error_handler(); to make sure that you have fully restored the PHP error handler as there is no way of knowing which error handler is in use! This is so frustrating as I use PHP commercially to write software for banks, councils and various other large enterprises where the software mutates itself and forks new instances of itself which means the error handling is changed and requires changing back, but if at some point in the script the error handler has been changed by something else we have no way of knowing just how many times we need to call restore_error_handler before we are back with the error handler we need. I'm hoping it is clear now why we need a get_error_handler() and get_exception_handler(). ------------------------------------------------------------------------ [2012-08-25 14:16:26] matthew dot bonner at gmail dot com I'm not sure the focus was of the exception handler and the reason I bring this up is you have mentioned about restoring the exception handler, however I think this bug applies to exceptions as well. I think for security alone, you should be able to call get_error_handler as if a rogue script has overridden the error handler you have no way of knowing without changing the error handler. Because there is no get_error_handler() you have to type: function tempErrorHandler () {} $previousErrorHandler = set_error_handler('tempErrorHandler'); restore_error_handler(); Even worse, people are probably writing a function called get_error_handler() to do this because you haven't provided this functionality. This means when you come to implement something like this you will have to provide enough time for people to remove their own implementation of this function. Another issue is how to restore the original PHP error handler, take for instance the following scenario: function tempErrorHandler () {} function basicErrorHandler () {} set_error_handler('tempErrorHandler'); set_error_handler('basicErrorHandler'); Calling restore_error_handler() restores the tempErrorHandler, that's great, we now have an error handler that is doing nothing. Please seriously reconsider your stance on the functionality provided for both the error and exception handling. ------------------------------------------------------------------------ [2012-03-18 16:46:11] tyr...@php.net sorry for my last two changes about this issue. ------------------------------------------------------------------------ [2012-03-18 16:41:54] tyra3l at gmail dot com asd ------------------------------------------------------------------------ [2012-03-18 16:41:41] tyra3l at gmail dot com test ------------------------------------------------------------------------ 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 https://bugs.php.net/bug.php?id=54033 -- Edit this bug report at https://bugs.php.net/bug.php?id=54033&edit=1