Can I somehow check, if my script was canceled by die()
in register_shutdown_function()
?
Something like this:
register_shutdown_function('shutdown');
die('Calling die()');
function shutdown()
{
if (???)
{
// Script was canceled by die()
}
}
NOTE: On my website, I use Smarty. So maybe check, if $smarty->display()
was called or something like that?
Kind of... but you won't necessarily like how it has to be done.
Since there is no hook that allows you to check if
die
was called, you will have to somehow fake it. Assuming that you cannot touch all calls todie
, that leaves only one option: set some state that signifies "die
was called" by default, and remove that state only at the very end of your script, when you know that you are going to exit withoutdie
having been called earlier."Set some state" sounds suspiciously like global variables and that should be a last resort, so let's use a constant for state:
See it in action.