Description
Symfony version(s) affected: 4.3.10
Description
After updating from 4.3.9 to 4.3.10 the changes from #35094 lead to loading of lazy commands although they are not actually called. This occurs with commands where the first part of the name matches. For example if you have two lazy commands app:foo
and app:foo:bar
, and call bin/console app:foo
, then app:foo:bar
will also be instantiated. This should not happen according to the documentation (link). I think the problem is line 668 in Symfony\Component\Console\Application.php where the command always get instantiated even if it is a lazy command.
How to reproduce
- Create two lazy commands where the first part of the name matches, i.e.
app:foo
andapp:foo:bar
:
# App/Command/FooCommand.php
class FooCommand extends Command
{
protected static $defaultName = 'app:foo';
public function __construct(string $name = null)
{
var_dump('app:foo');
parent::__construct($name);
}
}
# App/Command/FooBarCommand.php
class FooBarCommand extends Command
{
protected static $defaultName = 'app:foo:bar';
public function __construct(string $name = null)
{
var_dump('app:foo:bar');
parent::__construct($name);
}
}
- Call
bin/console app:foo
. The console output shows thatFooBarCommand
get also instantiated.
Possible Solution
I think the problem is line 668 in Symfony\Component\Console\Application.php where the command always get instantiated just to get its name even if it is a lazy command.
Additional context
root@327000b4b57a:/var/www/portal# bin/console app:foo
/var/www/portal/src/Command/FooBarCommand.php:13:
string(11) "app:foo:bar"
/var/www/portal/src/Command/FooCommand.php:13:
string(7) "app:foo"
...