Repository navigation
[Core] Skip classes unknown to reflection instead of crashing in fetchClassLikeReflection - #8965
Merged
TomasVotruba merged 1 commit intoNov 17, 2026
Conversation
…hClassLikeReflection
A file with legacy syntax that PHPStan cannot parse, e.g. $value{0}, makes its classes unknown to the reflection provider while Rector still parses it with its own PHP 7.0 parser. Rules using fetchClassLikeReflection() threw 'Class should be known at this point' and Rector aborted the whole file, so rules like CurlyToSquareBracketArrayStringRector never ran on it.
samsonasik
approved these changes
Nov 17, 2026
Member
|
this should also fix rectorphp/rector#9958 I guess 👍 |
Member
|
Thank you 👍 |
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.
Rector parses files with its own PHP 7.0 parser, so legacy syntax like
$value{0}is fine for it. PHPStan cannot parse that syntax, so the classes of such a file are unknown to the reflection provider.AbstractRector::fetchClassLikeReflection()then threwClass "X" should be known at this point, and Rector aborted the whole file. Rules that could fix the file, e.g.CurlyToSquareBracketArrayStringRector, never ran on it.The method already returns
?ClassReflectionand all callers handlenull, so it now returnsnullfor an unknown class and the rule skips it.Added a skip fixture for
Php4ConstructorRector. It fails with the exception before this change and passes after.