0

I try to create a custom command which creates a test user in Symfony 6.0.6 (with PHP 8.1). I tried it with creating a custom command with the following console command:

php bin/console make:command

The command is successfully created under the Command folder, but when I try to run it app:create-user (even without editing the content) I get the following error:

TypeError {#121
  #message: "ContainerP1iOqdm\CreateUserCommand_c0d3a03::setName(): Return value must be of type ContainerP1iOqdm\CreateUserCommand_c0d3a03, App\Command\CreateUserCommand returned"
  #code: 0
  #file: "./var/cache/dev/ContainerP1iOqdm/CreateUserCommand_c0d3a03.php"
  #line: 136
  trace: {
    ./var/cache/dev/ContainerP1iOqdm/CreateUserCommand_c0d3a03.php:136 {
      ContainerP1iOqdm\CreateUserCommand_c0d3a03->setName(string $name): static^
      › 
      ›     return $this->valueHolderf0709->setName($name);
      › }
    }
    ./vendor/symfony/console/Command/LazyCommand.php:184 { …}
    ./vendor/symfony/console/Application.php:295 { …}
    ./vendor/symfony/framework-bundle/Console/Application.php:80 { …}
    ./vendor/symfony/console/Application.php:171 { …}
    ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54 { …}
    ./vendor/autoload_runtime.php:29 { …}
    ./bin/console:11 { …}
  }
}

I already tried to clear the cache, but without success. Even after trying to create a new command I still get the error. I hope someone can help me with.

T.Hijd
  • 15
  • 1
  • 8
  • The namespace is very odd. What is `ContainerP1iOqdm`? – Julien B. May 13 '22 at 03:40
  • Thank you for your reaction. It looks like this namespace is created by cache. The namespace should be App\Command\CreateUserCommand but im not sure why a container with name ContainerP1iOqdm is created everytime I try to run the command. – T.Hijd May 13 '22 at 13:35

1 Answers1

1

It's a bug in symfony: https://github.com/symfony/symfony/issues/46350

Disable lazy option for commands in config/service.yaml or config/service.php