Skip to content

Guard against recursive previous error handler forwarding#6825

Merged
sebastianbergmann merged 1 commit into
sebastianbergmann:13.2from
ostrolucky:fix/infinite-recursion
Jul 8, 2026
Merged

Guard against recursive previous error handler forwarding#6825
sebastianbergmann merged 1 commit into
sebastianbergmann:13.2from
ostrolucky:fix/infinite-recursion

Conversation

@ostrolucky

@ostrolucky ostrolucky commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix an infinite recursion in PHPUnit\Runner\ErrorHandler when 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 ErrorHandler while 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-lib for 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.

@sebastianbergmann sebastianbergmann self-assigned this Jul 8, 2026
@sebastianbergmann sebastianbergmann added type/bug Something is broken feature/test-runner CLI test runner feature/issues Issues related to handling of `E_*` emitted by the PHP runtime and `E_USER_*` emitted in PHP code labels Jul 8, 2026
@sebastianbergmann sebastianbergmann merged commit 9767e69 into sebastianbergmann:13.2 Jul 8, 2026
24 checks passed
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.67%. Comparing base (8f5180f) to head (9c65698).
⚠️ Report is 2 commits behind head on 13.2.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@sebastianbergmann

Copy link
Copy Markdown
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!

@ostrolucky

Copy link
Copy Markdown
Contributor Author

LGTM, nothing was hanging for me there at least

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

Labels

feature/issues Issues related to handling of `E_*` emitted by the PHP runtime and `E_USER_*` emitted in PHP code feature/test-runner CLI test runner type/bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants