Skip to content

[Core] Skip classes unknown to reflection instead of crashing in fetchClassLikeReflection - #8965

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
hmennen90:fix-php4-constructor-unknown-class
Nov 17, 2026
Merged

TomasVotruba merged 1 commit into
rectorphp:mainfrom
hmennen90:fix-php4-constructor-unknown-class

Conversation

@hmennen90

Copy link
Copy Markdown
Contributor

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 threw Class "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 ?ClassReflection and all callers handle null, so it now returns null for 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.

…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

Copy link
Copy Markdown
Member

this should also fix rectorphp/rector#9958 I guess 👍

@TomasVotruba
TomasVotruba merged commit f129548 into rectorphp:main Nov 17, 2026
51 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

Thank you 👍

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants