Skip to content

Fix formatter panic on anonymous classes - #18

Open
danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-anonymous-class
Open

danslo wants to merge 1 commit into
rectorphp:mainfrom
danslo:fix-anonymous-class

Conversation

@danslo

@danslo danslo commented Nov 16, 2026

Copy link
Copy Markdown

Formatting an anonymous class panics:

<?php $a = new class {};

The parser stores it as a StmtClass without a name, and the formatter's StmtClass visits the name unconditionally. The printer already skips a missing name.

The formatter now writes the space and the name only when there is one. Added formatter tests for new class {} and new class($a) extends bar { ... }.

An anonymous class is a StmtClass without a name, and the formatter
visited the name unconditionally.
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.

1 participant