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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.