Attached is a small patch that can let you do the following. If you set
a custom error handler via set_error_handler()
but don't want to
implement all the details of handling every single error level, now you
can simply handle the ones you are interested. Basically, if you return
1 from your error handler, then the PHP default error handler gets
invoked, otherwise nothing happens. So:
function my_notice_handler($type, $str, $file, $line, $context)
{
if ($type == E_NOTICE
|| $type == E_USER_NOTICE) {
/* do something /
return false;
} else {
/ let PHP default handler do it */
return true;
}
}
It's backwards compatible with previous functionality, i.e. if you don't
return anything, the default handler does not get invoked.
Do you think it's harmless enough to include in PHP 5?
- Andrei
Attached is a small patch that can let you do the following. If you set
a custom error handler viaset_error_handler()
but don't want to
implement all the details of handling every single error level, now you
can simply handle the ones you are interested. Basically, if you return
1 from your error handler, then the PHP default error handler gets
invoked, otherwise nothing happens. So:function my_notice_handler($type, $str, $file, $line, $context)
{
if ($type ==E_NOTICE
|| $type == E_USER_NOTICE) {
/* do something /
return false;
} else {
/ let PHP default handler do it */
return true;
}
}
The convention(*) for these kinds of things is generally to return
'true' when you've handled the message/event and want to discontinue
further processing. Returning 'false' indicates that you haven't
handled the event.
(*) I don't mean "PHP covention", but this is how most other messaging
systems work when chaining handlers.
It's backwards compatible with previous functionality, i.e. if you don't
return anything, the default handler does not get invoked.
This argument may overrule my preference, of course.
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)
Jon Parise wrote:
The convention(*) for these kinds of things is generally to return
'true' when you've handled the message/event and want to discontinue
further processing. Returning 'false' indicates that you haven't
handled the event.
You are right. That's how it should be done.
It's backwards compatible with previous functionality, i.e. if you don't
return anything, the default handler does not get invoked.This argument may overrule my preference, of course.
Since error_handler is called from inside PHP engine, there should be no
noticable BC problem. Only the case when developer calls his function
directly too and does so in if/while/etc might be problem. But I don't
think this is showstopper.
Anyway, neat feature, please add (after return value inversion).
Lenar