Is it possible in PHP to unregister a function (or all functions) set up with register_shutdown_function()?
Is it possible in PHP to unregister a function (or all functions) set up
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I do not believe you can. The only way to unregister a callback function is to wrap it in some sort of class that only actually calls it based on certain conditions. Like this handy function wrapper:
Basic usage:
To unregister
Now, when called, it will return false and not call your callback function. There might be a few ways to streamline this process, but it works.
One such way of streamlining it would be to put the actual registration of the callback into a method of the callback function, so the outside world does not have to have knowledge that the method you have to pass to register_shutdown_function is “call”.