-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Exit as late as possible #26012
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
Exit as late as possible #26012
Conversation
@alcaeus please review |
@@ -151,7 +151,9 @@ public static function register($mode = false) | |||
} | |||
|
|||
if ('weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) { | |||
exit(1); | |||
register_shutdown_function(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would be even better would be to defer the whole closure, so that deprecations triggered at shutdown time are also caught (and add a related test of course :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside being that if a shutdown function uses exit
and the whole closure is deferred too, then you won't get any deprecations. But I think catching shutdown time deprecations might outweight this, what do you think? If we want to go crazy, we may even reset the state after the first, non deferred display and if any deprecations are caught while shutting down, then display them in the deferred closure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you want, both are fine to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll see what I can manage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ended up "going crazy", tell me what you think
Best reviewed when ignoring whitespace @nicolas-grekas the second commit feels more like a feature than a bugfix to me. Would you be ok with moving it to a separate PR? |
|
||
1x: root deprecation | ||
|
||
Deprecations during shutdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please tell me if you want more emphasis here and how it should look like (ascii underline with =
signs, maybe?), and if I should also add some header for the previous section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not more than existing titles, so as is LGTM
} | ||
|
||
register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations) { | ||
if (array_sum(array_filter($deprecations, function ($key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls for a data structure refactoring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do a code-style fix for now :) the "if" should be on one line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"fixed" :P
echo "Deprecations during shutdown\n"; | ||
} | ||
$displayDeprecations($deprecations); | ||
if ($isFailing) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there are shutdown-time deprecations, shouldn't this fail also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
TBH, I'd still consider it a bugfix: the original bug was that any existing deprecations cause other shutdown handlers to be ignored. This is fixed in your first commit. Fixing that bug exposes another bug, namely that any deprecations happening in other shutdown handlers don't reported. This is fixed in your second commit. |
07fe27a
to
d0e85e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(failures should be fixed once merged up to master, isn't it?)
Correct, but let me try to test it on 5.4 to be 100% sure. |
Don't merge, I get this, which seems to be a bug since I used the same version as in Travis:
Then, with a
This can't work for php < 5.6 |
I fixed it however I could, it should be good to merge now (although Travis is still red) |
Why exactly do we have those |
Tested with |
register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) { | ||
foreach ($deprecations as $group => $arrayOrInt) { | ||
if (is_int($arrayOrInt) && $arrayOrInt > 0 || is_array($arrayOrInt) && count($arrayOrInt) > 0) { | ||
echo "Deprecations during shutdown\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small tweak: s/Deprecations during shutdown/Shutdown-time deprecations:/
9f71764
to
bf78d74
Compare
People might want to register other shutdown functions that should be able to control the exit code themselves, without the deprecation error handler taking over. The php manual says: > If you call exit() within one registered shutdown function, processing > will stop completely and no other registered shutdown functions will be > called. See https://secure.php.net/manual/en/function.register-shutdown-function.php
bf78d74
to
97370a3
Compare
Thank you @greg0ire. |
This PR was merged into the 2.7 branch. Discussion ---------- Exit as late as possible People might want to register other shutdown functions that should be able to control the exit code themselves, without the deprecation error handler taking over. The php manual says: > If you call exit() within one registered shutdown function, processing > will stop completely and no other registered shutdown functions will be > called. See https://secure.php.net/manual/en/function.register-shutdown-function.php | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. - Replace this comment by a description of what your PR is solving. --> Commits ------- 97370a3 [Bridge\PhpUnit] Exit as late as possible
People might want to register other shutdown functions that should be
able to control the exit code themselves, without the deprecation error
handler taking over. The php manual says:
See https://secure.php.net/manual/en/function.register-shutdown-function.php