Guard against recursive previous error handler forwarding#6825
Merged
sebastianbergmann merged 1 commit intoJul 8, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 13.2 #6825 +/- ##
============================================
+ Coverage 97.66% 97.67% +0.01%
- Complexity 8702 8705 +3
============================================
Files 868 868
Lines 26566 26570 +4
============================================
+ Hits 25945 25952 +7
+ Misses 621 618 -3 ☔ View full report in Codecov by Harness. |
Owner
|
Thank you! I refined your solution a bit in 120f4d2. Can you please check whether your problem is still solved after my changes? Thank you! |
Contributor
Author
|
LGTM, nothing was hanging for me there at least |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix an infinite recursion in
PHPUnit\Runner\ErrorHandlerwhen PHPUnit forwards an issue to a previously registered error handler and that handler re-enters PHPUnit's error handling.Problem
PHPUnit since 75d896e changed its error handling so that a previously registered error handler is invoked before PHPUnit records an issue. This is important for compatibility with handlers that convert PHP warnings, notices, or deprecations into exceptions: in those cases, the error should become normal control flow observed by the test runner rather than being reported as a PHPUnit issue.
However, this forwarding can create a recursive call cycle when the previous handler triggers another PHP issue or otherwise calls back into PHPUnit's
ErrorHandlerwhile PHPUnit is already forwarding an issue to it. In that situation, PHPUnit can repeatedly forward between handlers instead of reporting the warning normally, which may lead to a hang, stack exhaustion, or a segmentation fault depending on the environment.A real-world example of this showed up in a functional test using
mlocati/ip-libfor CIDR parsing together with Symfony's error handling bridge. That combination interacts with PHP's error-handler stack while warnings are being processed, and with PHPUnit's previous-handler forwarding in place it could trigger the recursive error-handler path. The observed result was that the test process no longer completed reliably and could hang indefinitely or crash instead of producing a normal PHPUnit warning/error report.