Skip to content

Built-in Cache attribute with variables not working #48506

@stephanvierkant

Description

@stephanvierkant

Symfony version(s) affected

6.2.0

Description

I'm trying to switch from the SensioFrameworkExtraBundle to the new built-in cache attributes from Symfony 6.2, but I'm getting an error.

- #[\Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache(maxage: 120, lastModified: 'entity.getUpdatedAt()', etag: 'entity.getETag()')]
+ #[\Symfony\Component\HttpKernel\Attribute\Cache(maxage: 120, lastModified: 'entity.getUpdatedAt()', etag: 'entity.getETag()')]
public function someAction(Entity $entity) : Response
{
}

This used to work, but now it gives an error:

Variable "entity" is not valid around position 1 for expression entity.getUpdatedAt().

Any idea why this doesn't work? I can dive into it, but maybe someone has already found out why this doesn't work.

How to reproduce

final class Controller extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
    #[\Symfony\Component\HttpKernel\Attribute\Cache(maxage: 120, lastModified: 'entity.getUpdatedAt()', etag: 'entity.getETag()')]
    public function someAction(Entity $entity) : Response
    {
    }
}

Possible Solution

No response

Additional Context

No response

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