Skip to content

ReadOnlyAnonymousClassRector on anon class with Attributes #9932

Closed
rectorphp/rector-src
#8665

Description

@moshe-autoleadstar

https://getrector.com/demo/4b154cf5-1d57-426c-9b3b-ec4632eb1c4b
given this code:

$attributed = new #[Tries(5)] class(4)
{
    public function __construct(
        private readonly int $attempts,
    ) {}

    public function attempts(): int
    {
        return $this->attempts;
    }
};

it tries to do this:

$attributed = new #[Tries(5)] readonly class(4)
{
    public function __construct(
        private int $attempts,
    ) {}

    public function attempts(): int
    {
        return $this->attempts;
    }
};

but fails with Encountered unexpected token

Activity

  1. TomasVotruba commented on Oct 15, 2026

    @TomasVotruba
    Member

    Thanks for reporting 👍

    Fixed in rectorphp/rector-src#8665

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions