Skip to content

Support attributes on anonymous classes (new #[Attr] class {}) - #7

Merged
TomasVotruba merged 1 commit into
mainfrom
add-attributes-on-anonymous-class
Oct 5, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
add-attributes-on-anonymous-class

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Problem

An attribute group between new and an anonymous class failed to parse:

$command = new #[AsCommand(name: 'foo')] class extends Command {};

with unexpected T_ATTRIBUTE. This is valid since PHP 8.0 and appears in e.g. symfony/console's tests.

Change

  • Grammar (internal/php8/php8.y): add T_NEW attributes anonymous_class to new_non_dereferenceable; the attribute groups attach to the anonymous class node. Adds zero new goyacc conflicts.
  • Regenerated php8.go.
  • The printer already emits StmtClass.AttrGroups, so these round-trip unchanged.
  • Added internal/php8/attributes_on_anonymous_class_test.go (parse + print-back-unchanged).

Verification

Full suite and golangci-lint pass. With reco pointed at this branch, a type-coverage scan of symfony/console now completes with no syntax errors and no skipped files (combined with the octal and DNF fixes already released).

An attribute group between new and an anonymous class, e.g.
new #[AsCommand(name: 'foo')] class extends Command {}, is now parsed and the
attribute groups attach to the class node, so it prints back unchanged.

Adds zero new goyacc conflicts.
@TomasVotruba
TomasVotruba merged commit 1cb19a0 into main Oct 5, 2026
2 of 5 checks passed
@TomasVotruba
TomasVotruba deleted the add-attributes-on-anonymous-class branch October 5, 2026 20:19
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