Skip to content

[Console] Using the --profile option throws a TypeError in the TraceableCommand class #62626

@viccherubini

Description

@viccherubini

Symfony version(s) affected

7.4

Description

Using the --profile option to debug a console command causes a TypeError to be thrown by the TraceableCommand class on line 172.

TypeError {#253
  #message: "ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, App\Command\HelloWorldCommand given"
  #code: 0
  #file: "./vendor/symfony/console/Command/TraceableCommand.php"
  #line: 172
  trace: {
    ./vendor/symfony/console/Command/TraceableCommand.php:172 { …}
    ./vendor/symfony/console/Command/TraceableCommand.php:71 { …}
    ./vendor/symfony/framework-bundle/Console/Application.php:115 { …}
    ./vendor/symfony/console/Application.php:356 { …}
    ./vendor/symfony/framework-bundle/Console/Application.php:77 { …}
    ./vendor/symfony/console/Application.php:195 { …}
    ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49 { …}
    ./vendor/autoload_runtime.php:32 { …}
    ./bin/console:15 {
      ›
      › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
      ›
      arguments: {
        "/path/to/symfony/app/console-test/vendor/autoload_runtime.php"
      }
    }
  }
}

How to reproduce

  1. Create a brand new Symfony 7.4 application with the command: symfony new --webapp --version="7.4.x" console-test
  2. Create a file in src/Command/ named HelloWorldCommand.php with the following contents:
<?php

namespace App\Command;

use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'app:hello:world')]
final readonly class HelloWorldCommand
{
    public function __invoke(SymfonyStyle $io, #[Argument] string $name): int
    {
        $io->title('Hello World');
        $io->writeln(sprintf('Hello, %s!', $name));

        return Command::SUCCESS;
    }
}
  1. Attempt to run the command with the --profile option to see the error above: php bin/console app:hello:world Vic --profile

Notes

  • Running the command without the --profile option works as expected.
  • Doesn't matter if the development web server is running or not.
  • Doesn't matter where the --profile option is located in the command line. Both php bin/console --profile app:hello:world Vic and php bin/console app:hello:world --profile Vic fail.

Possible Solution

No response

Additional Context

Was this possibly broken by #61134 and #61138? I thought I messed up the migration from 7.3.7 to 7.4.0, but getting the same error with a brand new stock install of 7.4.0 confirmed it's not my actual codebase.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions