Symfony: Deprecated @Route and @Method Annotations

Doing a composer update on my pet project got me a bunch of deprecation notices:

The “Sensio\Bundle\FrameworkExtraBundle\Configuration\Route” annotation is deprecated since version 5.2. Use “Symfony\Component\Routing\Annotation\Route” instead.

OK, that sounds familiar..
I’ve always had a dilemma when auto-importing @Route in PHPStorm,which of the two should I choose.
Guess I went with the wrong one 🙁
Correcting was easy, yet boring:

The other depreecation looked similar:

The “Sensio\Bundle\FrameworkExtraBundle\Configuration\Method” annotation is deprecated since version 5.2. Use “Symfony\Component\Routing\Annotation\Route” instead.

OK, what? @Method is deprecated, use @Route ? Go home, Symfony, you are drunk 😀
Well.. turns out the message is sane. The new way of specifying the HTTP method is in the @Route annotation, under methods key.
So, I’ve corrected:

To this:

After updating all the annotations, I was left was a cryptic deprecation notice:

Enabling the “sensio_framework_extra.router.annotations” configuration is deprecated since version 5.2. Set it to false and use the “Symfony\Component\Routing\Annotation\Route” annotation from Symfony itself.

I say “cryptic” because I did not enable that configuration myself. It was enabled by default. And there’s a pull request to make it disabled by default.
Until that pull request gets merged, the fix that worked for me was to create a config/packages/framework_extra.yaml and disable those annotations explicitly:

Yay! No more deprecation notices 🙂

Also published on Medium.

8 thoughts on “Symfony: Deprecated @Route and @Method Annotations”

    1. – to change deprecated annotations, you’d have to update all of your controller files
      – to fix the other deprecation, you have to edit `app/config/config.yml` (for Symfony 3.4) or config/packages/framework_extra.yaml (for Symfony 4)

Leave a Reply

Your email address will not be published. Required fields are marked *