简体   繁体   English

在 Symfony 6 中运行(新)自定义命令会出错

[英]Running a (fresh) custom command in Symfony 6 gives an error

I try to create a custom command which creates a test user in Symfony 6.0.6 (with PHP 8.1).我尝试创建一个自定义命令,该命令在 Symfony 6.0.6(使用 PHP 8.1)中创建一个测试用户。 I tried it with creating a custom command with the following console command:我尝试使用以下控制台命令创建自定义命令:

php bin/console make:command

The command is successfully created under the Command folder, but when I try to run it app:create-user (even without editing the content) I get the following error:该命令已在 Command 文件夹下成功创建,但是当我尝试运行它时 app:create-user (即使没有编辑内容)我收到以下错误:

TypeError {#121
  #message: "ContainerP1iOqdm\CreateUserCommand_c0d3a03::setName(): Return value must be of type ContainerP1iOqdm\CreateUserCommand_c0d3a03, App\Command\CreateUserCommand returned"
  #code: 0
  #file: "./var/cache/dev/ContainerP1iOqdm/CreateUserCommand_c0d3a03.php"
  #line: 136
  trace: {
    ./var/cache/dev/ContainerP1iOqdm/CreateUserCommand_c0d3a03.php:136 {
      ContainerP1iOqdm\CreateUserCommand_c0d3a03->setName(string $name): static^
      › 
      ›     return $this->valueHolderf0709->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 { …}
  }
}

I already tried to clear the cache, but without success.我已经尝试清除缓存,但没有成功。 Even after trying to create a new command I still get the error.即使在尝试创建新命令后,我仍然会收到错误消息。 I hope someone can help me with.我希望有人可以帮助我。

It's a bug in symfony: https://github.com/symfony/symfony/issues/46350这是 symfony 中的一个错误: https://github.com/symfony/symfony/issues/46350

Disable lazy option for commands in config/service.yaml or config/service.php禁用config/service.yamlconfig/service.php中命令的lazy选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM