-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Restore exception handler after running it #13686
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
GH-13446: Exception handler is restored after is has finished | ||
--FILE-- | ||
<?php | ||
function exception_handler($ex) { | ||
echo 'Exception caught: ', $ex->getMessage(), "\n"; | ||
} | ||
set_exception_handler('exception_handler'); | ||
|
||
register_shutdown_function(function () { | ||
echo set_exception_handler(null), "\n"; | ||
restore_exception_handler(); | ||
}); | ||
|
||
throw new Exception('Test'); | ||
?> | ||
--EXPECT-- | ||
Exception caught: Test | ||
exception_handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
GH-13446: Exception handler attempting to free itself | ||
--FILE-- | ||
<?php | ||
$x = new \stdClass(); | ||
$handler = function ($ex) use (&$handler, $x) { | ||
$handler = null; | ||
var_dump($x); | ||
}; | ||
unset($x); | ||
set_exception_handler($handler); | ||
throw new Exception('Unhandled'); | ||
?> | ||
--EXPECT-- | ||
object(stdClass)#1 (0) { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--TEST-- | ||
GH-13446: Exception handler isn't restored if it is previously modified | ||
--FILE-- | ||
<?php | ||
function exception_handler_1($ex) { | ||
echo "Handler 1\n"; | ||
set_exception_handler('exception_handler_2'); | ||
} | ||
|
||
function exception_handler_2($ex) { | ||
echo "Handler 2\n"; | ||
} | ||
|
||
set_exception_handler('exception_handler_1'); | ||
|
||
register_shutdown_function(function () { | ||
echo set_exception_handler(null), "\n"; | ||
restore_exception_handler(); | ||
}); | ||
|
||
throw new Exception(); | ||
?> | ||
--EXPECT-- | ||
Handler 1 | ||
exception_handler_2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
GH-13446: Exception handler isn't restored if stack is empty | ||
--FILE-- | ||
<?php | ||
function exception_handler() { | ||
echo "Handler\n"; | ||
restore_exception_handler(); | ||
restore_exception_handler(); | ||
} | ||
set_exception_handler('exception_handler'); | ||
|
||
register_shutdown_function(function () { | ||
var_dump(set_exception_handler(null)); | ||
restore_exception_handler(); | ||
}); | ||
|
||
throw new Exception(); | ||
?> | ||
--EXPECT-- | ||
Handler | ||
NULL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.