2

I am quite confused by the following deprecation notice in my Symfony 5.4 application.

The "Symfony\Component\Console\Command\Command::$defaultName" property is considered final. You should not override it in "CRMPiccoBundle\Console\Command\Aws\Cognito\CreateUser".

In my code I have the following:

class CreateUser extends Command
{
    protected static $defaultName = 'crmpiccobundle:aws:cognito:createuser';

...which aligns with the documentation.

The parent Command class looks like this:

/**
 * @var string|null The default command name
 */
protected static $defaultName;

All my commands are now outputting a deprecation notice, which is not ideal.

composer show | grep console
symfony/console                      v5.4.19            Eases the creation of beautiful and testable command line interfaces

What am I misunderstanding here? I'm on PHP 8.1.14.

crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • As you probably also already discovered the $defaultName property is [deprecated](https://github.com/symfony/symfony/pull/45361), but I'm also very confused by the deprecation message you're seeing. – Pieter van den Ham Feb 01 '23 at 10:53
  • 1
    Please share more details. I can't find that error message within Symfony's code – Nico Haase Feb 01 '23 at 12:49
  • 1
    Maybe https://github.com/symfony/symfony/pull/45360 is involved here? Do you probably use `symfony/error-handler` v6.1 or later? – Nico Haase Feb 01 '23 at 12:55
  • 2
    It is puzzling. I made a fresh 5.4.20 app, added a command using static for the name/description and I am not getting any notices. The message you are showing is not a deprecation notice. It is an actual warning about overriding final variables. I think it is just a coincidence that Symfony has deprecated the variables in 6.1. Is CRMPiccoBundle your bundle? Double check that UserCommand is extending `Symfony\Component\Console\Command\Command` and not some other base command class. It makes no sense to have final on classes designed to be extended. – Cerad Feb 01 '23 at 14:40
  • You shouldn't be receiving a deprecation notice for final properties in Symfony 5.4.x, what does `composer show | grep symfony` output? – Will B. Feb 02 '23 at 13:59
  • @NicoHaase Thanks for your comment. I downgrade `symfony/error-handler` and it resolved the problem. I'm not entirely sure what brought in version 6, but a downgrade to v5 has cleared these up for now. – crmpicco Feb 03 '23 at 07:21

1 Answers1

2

First: Deprecations are not errors You are not required to fix anything until you upgrade to Symfony 6. Then you must fix the error.

Second, like many documentations, the Symfony docs sometimes lag behind the development. The new method is documented here

So you can switch to using this

#[AsCommand(
    name: 'crmpiccobundle:aws:cognito:createuser',
    description: 'Creates a new user.',
)]
class CreateUser extends Command
{
...
craigh
  • 1,909
  • 1
  • 11
  • 24
  • 1
    Of course it is not actually a deprecation notice that is being generated. Your suggestion might make the message go away but what is causing the message is still a bit of a mystery. – Cerad Feb 01 '23 at 14:53
  • Thanks for this. Although, I don't think anyone said the deprecations were errors, did they? I quite like the `AsCommand` syntax but i'm happy to downgrade `symfony/error-handler` for now. – crmpicco Feb 03 '23 at 07:21