-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed as not planned
Description
Symfony version(s) affected
7.2.9
Description
Running a command using the standalone Console component throws an error:
PHP Fatal error: Uncaught TypeError: Symfony\Component\Console\Application::add(): Argument #1 ($command) must be of type Symfony\Component\Console\Command\Command, App\MyCommand given, called in /var/www/html/bin/console.php on line 12 and defined in /var/www/html/vendor/symfony/console/Application.php:53
add() expects a Command, but the example doesn't extend anything, since it uses the AsCommand attribute instead.
How to reproduce
- Install dependencies:
composer require symfony/console
- Create a basic command, per the documentation:
#[AsCommand(name: 'app:my-command')]
final readonly class MyCommand
{
public function __invoke(): int
{
return Command::SUCCESS;
}
}- Create the console app, per the documentation:
#!/usr/bin/env php
<?php
require __DIR__.'/../vendor/autoload.php';
use App\MyCommand;
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new MyCommand());
$application->run();- Run:
bin/application.php app:my-command
Possible Solution
No response
Additional Context
No response