-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DX][Console] Improve error message when the parent constructor is not called #25423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's probably because the Ideally I'd not see the parent class at all, just like I can do with controllers. I would like to see a form of composition over inheritance here to solve this issue. final class MyCommand implements CommandInterface
{
public static function configure(CommandConfiguratorInterface $config)
{
$config->setName('foo:bar');
$config->setDescription('...');
$config->addArgument('some-argument');
}
public function execute(InputInterface $input, OutputInterface $output)
{
// do something awesome
}
} Could be solved by simply wrapping this inside an instance of the current Command class. |
@iltar the issue is that any static is out of any service layer. I know that some projects do fetch configuration of their commands via a DB call. And that's fine. So, "object oriented" is a requirement here. |
Both methods could be supported, my proposal would be merely feeding the actual command class with information, which can be cached during container building and would thus make them very lazy. As the current situation is still possible, it wouldn't make an existing solutions impossible to build. final class CommandWrapper extends Command
{
public function __construct(CommandInterface $command, CommandMetadata $metadata)
{
// ...
}
protected function configure()
{
// use the CommandMetadata to configure $this
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->command->execute($input, $output);
}
} |
I just created a command with the maker bundle, added a constructor that didn't call the parent, and this is the message I'm seeing:
Looks perfect to me, nothing to do here. What did I miss? |
Can we close? I can't reproduce either |
If you add a constructor in your command and forget to add the
parent::__construct()
call, you'll end up with this misleading error:This was not a very important issue in the past, but now that adding a constructor is the recommended way to inject services, we're starting to get issue reports about this (e.g. symfony/symfony-docs#8843 (comment)).
Could we detect this issue and change the error message to tell the user that they must add the
parent::__construct()
call?The text was updated successfully, but these errors were encountered: