Fix GH-20112: Fatal error during autoloading of complex inheritance chain#21573
Open
iliaal wants to merge 1 commit intophp:PHP-8.4from
Open
Fix GH-20112: Fatal error during autoloading of complex inheritance chain#21573iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal wants to merge 1 commit intophp:PHP-8.4from
Conversation
…e chain When load_delayed_classes() is called recursively (e.g., autoloading a class whose linking triggers another class with unresolved variance), the shared delayed_autoloads table may contain entries from an outer caller whose dependencies are not yet available. The inner call would attempt to load these unrelated entries, causing a fatal error when their parent class is still mid-linking higher up the call stack. In nested calls, catch such loading failures and re-append the entry for the outer caller to process later, when the dependency chain is complete. A consecutive-failure counter ensures no infinite retry loops. Closes phpGH-20112
This was referenced Mar 29, 2026
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.
Fixes #20112
load_delayed_classes()iterates a sharedCG(delayed_autoloads)hash table. When autoloading triggers linking of another class with unresolved variance, the recursive call walks the same table and can pull entries that belong to an outer caller. If that entry's parent is still mid-linking up the call stack, the load hits a fatal error.The fix adds a nesting depth counter. At depth > 1, if a class doesn't load and isn't in the class table, we catch the exception and re-append the entry for the outer caller to pick up once its dependency chain completes. A consecutive-failure count breaks out when no progress is possible. At depth 1, failures propagate as before.
Targeting 8.4 since the bug has existed since PHP 8.1 (bisected to a38f4f9). No performance impact; the new code only runs on the exception path.