致命错误:在Composer安装后,方法class@anonymous::__toString()不得抛出异常
你好,当我进行 composer install 并且缓存:clear 时出现错误。
- 我使用Symfony 4.1
- 我已经删除了/var & /vendor
- 我在 Docker (php)
composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package symfony/lts is abandoned, you should avoid using it. Use symfony/flex instead.
Package symfony/webpack-encore-pack is abandoned, you should avoid using it. Use symfony/webpack-encore-bundle instead.
Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.
Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
102 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Run composer recipes at any time to see the status of your Symfony recipes.
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 255
!! Xdebug: [Config] Invalid mode '1' set for 'xdebug.mode' configuration setting (See: https://xdebug.org/docs/errors#CFG-C-MODE)
!!
!! Fatal error: Method class@anonymous::__toString() must not throw an exception, caught SymfonyComponentDependencyInjectionExceptionAutowiringFailedException: in /var/www/symfony/vendor/symfony/dependency-injection/Compiler/AutowirePass.php on line 236
!!
!! Call Stack:
!! 0.0004 403344 1. {main}() /var/www/symfony/bin/console:0
!! 0.1875 2144496 2. SymfonyBundleFrameworkBundleConsoleApplication->run($input = class SymfonyComponentConsoleInputArgvInput
!! 5.8396 32162400 18. SymfonyComponentDependencyInjectionCompilerAutowirePass->SymfonyComponentDependencyInjectionCompiler{closure:/var/www/symfony/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:229-241}() /var/www/symfony/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:261
!!
!!
!! In AutowirePass.php line 236:
!!
!! Error: Method class@anonymous::__toString() must not throw an exception, ca
!! ught SymfonyComponentDependencyInjectionExceptionAutowiringFailedExcept
!! ion:
!!
!!
!!
Script @auto-scripts was called via post-install-cmd
回答
发生此错误是因为新的 XDebug 3.0 与 Symfony 框架不兼容
有两种可能的方法来修复它:
- 使用旧版本的 XDebug:
- 强制安装旧版本的 xdebug
sudo pecl install -f xdebug-2.9.8 - 通过检查
php -v输出中的XDebug 版本确保扩展处于活动状态 - 重建SF缓存
bin/console cache:clear
- 临时关闭 XDebug 并重建缓存(更像是解决方法):
- 使用 cli 进入您的 docker 容器(或在您的主机上运行以下内容,具体取决于您的设置)
- 关闭调试
export XDEBUG_MODE=off - 重建缓存
bin/console cache:clear - 再次打开 XDebug
export XDEBUG_MODE=debug,develop(或任何您用作模式的东西)
关注此问题以更新有关任何其他解决方案的信息
THE END
二维码