Jump to content

[SOLVED] Set_error_handler die but return true


inactive

Recommended Posts

Hey homies,

 

Is there anyway in the function I set in set_error_handler() to return true, and die?

 

My code:

<?php
set_error_handler('my_error_handler');

function my_error_handler($errno, $errstr, $errfile, $errline) {
// ... handle error here ... //
}

echo  1/0; // generates a warning
trigger_error('Some Other Error', E_USER_ERROR); // generates user error

?>

 

What the my_error_handler() function does will depend on the error type:

 

1) In the case of the warning, after handling the error, it will return true, so that the normal PHP error handler will log the error in the normal error log, and then it will let the rest of the script proceed. This works great.

 

2) In the case of the user error, I need it to handle the error, then return true, so that the normal PHP error handler will log the error in the normal error log, and then exit. I cannot get this to work.  ???

 

Is there a way to return true, and exit/die?

 

If I don't exit/die, the rest of the script will continue to run, with detrimental results. If I do exit, then it is not possible to return true, which means the error won't be logged properly by the normal PHP error handler.

 

I.e:

<?php
exit(); // script will exit,
return true; // but will not return true (obviously, as the script has already terminated)
?>

<?php
return true; // script will return true,
exit(); // but as it has now jumped out of this function, will now not exit
?>

 

Any ideas? Is this even possible?

 

Thanks in advance.

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.