-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected
6.0.8
Description
Hi!
I know that the correct way to make a command lazy is:
protected static $defaultName = 'app:test';
protected static $defaultDescription = 'description';
but if we want to use lazy
attribute with command in service.yaml
App\Command\:
resource: '../src/Command'
lazy: true
there will be the an error:
php bin/console app:test
TypeError {#96
#message: "ContainerLegSm4V\TestCommand_d286c1a::setName(): Return value must be of type ContainerLegSm4V\TestCommand_d286c1a, App\Command\TestCommand returned"
#code: 0
#file: "./var/cache/dev/ContainerLegSm4V/TestCommand_d286c1a.php"
#line: 143
trace: {
./var/cache/dev/ContainerLegSm4V/TestCommand_d286c1a.php:143 {
ContainerLegSm4V\TestCommand_d286c1a->setName(string $name): static
›
› return $this->valueHolder1624a->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 { …}
}
}
2022-05-14T10:41:08+00:00 [critical] Uncaught Error: ContainerLegSm4V\TestCommand_d286c1a::setName(): Return value must be of type ContainerLegSm4V\TestCommand_d286c1a, App\Command\TestCommand returned
The error started appearing after this commit which added : static
return type to setName()
function in Symfony\Component\Console\Command\Command.php
public function setName(string $name): static
How to reproduce
git clone git@github.com:mrsuh/issue-symfony-console.git && cd issue-symfony-console
composer install
php bin/console app:test
Possible Solution
I think
- it's wrong to add
lazy
attribute to an already lazy command, but it's worked before and we need to fix it. Maybe we can replacestatic
return type withself
? - we need to add a note to documentation not to use
static
return type inlazy
services
Additional Context
No response