Skip to content

Cache error while using anonymous class inside controller #30395

@zim32

Description

@zim32

Symfony version(s) affected: 4.2.3

Description
I got error Uncaught PHP Exception Symfony\Component\Cache\Exception\InvalidArgumentException: "Cache key "@anonymous" contains reserved characters {}()/@:
In my controller action method I am using anonymous class

...
$form = $this->createForm(SomeType::class, $this->getDataWrapper($data));
...
protected function getDataWrapper($data)
    {
        return new class ($data) {
            protected $data;

            public function __construct($data)
            {
                $this->data = $data;
            }

            public function getData() {
                return $this->data->getQuery()->getResult();
            }

            public function setData($data) {
                $this->data = $data;
            }
        };
    }

I was able to fix this by using ordinary, not anonymous class, but I think it should be fixed somehow

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions