Skip to content

[Php83] Skip ReadOnlyAnonymousClassRector on anonymous class with attributes - #8665

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-fix-9932-anon-attr
Oct 15, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-fix-9932-anon-attr

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9932

An anonymous class with an inline attribute, e.g. new #[Tries(5)] class(4) { ... }, crashed ReadOnlyAnonymousClassRector with System error: "Encountered unexpected token".

The attribute sits between new and class in the token stream, and the format-preserving printer cannot insert the added readonly modifier at that position. This skips such anonymous classes to avoid the crash.

@TomasVotruba
TomasVotruba force-pushed the tv-fix-9932-anon-attr branch from 58dce6e to 005d1ea Compare October 15, 2026 14:48
@TomasVotruba
TomasVotruba merged commit 3871a13 into main Oct 15, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-fix-9932-anon-attr branch October 15, 2026 14:51
@samsonasik

Copy link
Copy Markdown
Member

I created a PR to php-parser to properly fix it:

@TomasVotruba

Copy link
Copy Markdown
Member Author

Even better 👍

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.

ReadOnlyAnonymousClassRector on anon class with Attributes

2 participants