Skip to content

Skip bailout for unwind and graceful exception from zend_throw_exception_internal() #19168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iluuu1994
Copy link
Member

Fixes GH-18619

@iluuu1994 iluuu1994 changed the title Skip bailout for exit and graceful exception from zend_throw_exception_internal() Skip bailout for unwind and graceful exception from zend_throw_exception_internal() Jul 18, 2025
@bwoebi
Copy link
Member

bwoebi commented Jul 22, 2025

Ummm, I thought calling exit in register_shutdown_function was the approved way of stopping to process shutdown handlers / destructors?

@iluuu1994
Copy link
Member Author

https://www.php.net/manual/en/function.register-shutdown-function.php

If you call exit() within one registered shutdown function, processing will stop completely and no other registered shutdown functions will be called.

You are right. I was not aware of this rule. I presume the same should apply to error handlers?

@bwoebi
Copy link
Member

bwoebi commented Jul 22, 2025

Yes, I'd say so. After all exception handlers are sort of processed as part of the relevant shutdown handlers.

And just for the record, destructors say the same thing:

The destructor will be called even if script execution is stopped using exit(). Calling exit() in a destructor will prevent the remaining shutdown routines from executing.
https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.destructor

@iluuu1994
Copy link
Member Author

Ok, TIL. The test is still wrong, as in that case the shutdown handler shouldn't run. So let me change the patch.

@bwoebi
Copy link
Member

bwoebi commented Jul 22, 2025

@iluuu1994 Oh, the Zend/tests/gh18619.phpt is right. This runs before the shutdown sequence. I thought you meant exit; calls happening in exception handlers executed in response to exceptions thrown in register_shutdown_function.

@iluuu1994
Copy link
Member Author

But then Zend/tests/bug62763.phpt looks wrong too, though. Or does this imply that exit() from shutdown handlers just stops further shutdown handlers, but not destructors? That doesn't make a lot of sense imo.

@bwoebi
Copy link
Member

bwoebi commented Jul 22, 2025

Yes, I agree that this is weird. The wording in the docs sort of support both interpretations:

processing will stop completely [... okay, no destructors either?!] and no other registered shutdown functions will be called [huh, only no other shutdown handlers, but also destructors???].

So, the docs should probably be a bit less ambiguous in either direction and the implementation should follow that.
I think I agree with the interpretation that it also should prevent destructors.
But changing that might be PHP-8.5 stuff rather than 8.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

set_exception_handler not restored if calling exit within itself
2 participants