Jump to content

On Error Function Call


objnoob

Recommended Posts

I'd like to set my own error handler function to clear some session variables, but I do not want to completely replace php's internal error handler message reporting.

 

Is there any way to mimic the internal error message reporting so I can define my own error handler function.

 

function myErrorHandler(){
  unset($_SESSION['var']);

  // HERE EXECUTE Normal PHP error message reporting

}

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/218874-on-error-function-call/
Share on other sites

I don't think you can wrap PHP's default error handler without replicating it in your own code.

 

I think the closest you can come is to use set_error_handler to define your own error handling function.  Have your custom error handler unset the session vars, call restore_error_handler(), then call trigger_error() using error_get_last() to generate the error string.

 

Edit: Is there a reason you want to use PHP's default error handler?  If its just to save you the hassle of coding, check out the docs on set_error_handler.  There are some decent implementations in the user comments.

I read the documentation on set_error_handler function, and php docs state:

 

"It is important to remember that the standard PHP error handler is completely bypassed for the error types specified by error_types unless the callback function returns FALSE."

 

So, I'll just return false in my custom handler function. This is exactly what I was looking for.

 

Thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.