致命错误:方法 class@anonymous::__toString() 在作曲家安装后不得抛出异常

Posted

技术标签:

【中文标题】致命错误:方法 class@anonymous::__toString() 在作曲家安装后不得抛出异常【英文标题】:Fatal error: Method class@anonymous::__toString() must not throw an exception after composer install 【发布时间】:2021-03-09 07:09:32 【问题描述】:

你好,我在安装 composer 时遇到了一个错误,它确实缓存了:清除。

我使用 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 Symfony\Component\DependencyInjection\Exception\AutowiringFailedException:  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. Symfony\Bundle\FrameworkBundle\Console\Application->run($input = class Symfony\Component\Console\Input\ArgvInput 
!!      5.8396   32162400  18. Symfony\Component\DependencyInjection\Compiler\AutowirePass->Symfony\Component\DependencyInjection\Compiler\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 Symfony\Component\DependencyInjection\Exception\AutowiringFailedExcept  
!!    ion:                                                                         
!!                                                                                 
!!  
!!  
Script @auto-scripts was called via post-install-cmd

我尝试关注此issue,但没有任何效果(对我来说在开发中不起作用)

我的 composer.json


    "type": "project",
    "license": "proprietary",
    "require": 
        "php": "^7.1.3",
        "ext-iconv": "*",
        "accord/mandrill-swiftmailer-bundle": "^1.3",
        "api-platform/api-pack": "^1.1",
        "composer/package-versions-deprecated": "1.11.99.1",
        "doctrine/doctrine-bundle": "^1.0",
        "doctrine/doctrine-migrations-bundle": "^2.2",
        "doctrine/orm": "^2.7",
        "friendsofsymfony/ckeditor-bundle": "^2.1",
        "friendsofsymfony/user-bundle": "~2.0",
        "knplabs/knp-paginator-bundle": "^4.0",
        "paragonie/random_compat": "^2.0",
        "ramsey/uuid-doctrine": "^1.4",
        "sensio/framework-extra-bundle": "^5.1",
        "sentry/sentry-symfony": "^3.1",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony/asset": "^4.1",
        "symfony/console": "^4.1",
        "symfony/dotenv": "^4.1",
        "symfony/expression-language": "^4.1",
        "symfony/flex": "^1.0",
        "symfony/form": "^4.1",
        "symfony/framework-bundle": "^4.1",
        "symfony/lts": "^4@dev",
        "symfony/monolog-bundle": "^3.1",
        "symfony/process": "^4.1",
        "symfony/security-bundle": "^4.1",
        "symfony/serializer-pack": "*",
        "symfony/swiftmailer-bundle": "^3.1",
        "symfony/translation": "^4.1",
        "symfony/twig-bundle": "^4.1",
        "symfony/validator": "^4.1",
        "symfony/web-link": "^4.1",
        "symfony/webpack-encore-pack": "*",
        "symfony/yaml": "^4.1",
        "vich/uploader-bundle": "^1.9"
    ,
    "require-dev": 
        "hautelook/alice-bundle": "^2.0",
        "doctrine/data-fixtures": "^1.3",
        "behat/behat": "^3.4",
        "symfony/debug-pack": "*",
        "symfony/maker-bundle": "^1.0",
        "symfony/phpunit-bridge": "^4.1",
        "symfony/profiler-pack": "*",
        "symfony/test-pack": "^1.0",
        "symfony/web-server-bundle": "^4.1"
    ,
    "config": 
        "preferred-install": 
            "*": "dist"
        ,
        "sort-packages": true
    ,
    "autoload": 
        "psr-4": 
            "App\\": "src/"
        
    ,
    "autoload-dev": 
        "psr-4": 
            "App\\Tests\\": "tests/"
        
    ,
    "replace": 
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    ,
    "scripts": 
        "auto-scripts": 
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        ,
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    ,
    "conflict": 
        "symfony/symfony": "*"
    ,
    "extra": 
        "symfony": 
            "allow-contrib": false
        
    

如果有人有一个愚蠢的想法,我会接受。我已经卡了很久了……

【问题讨论】:

嗨,我在使用 php 7.2 和 Xdebug v3.0.0 时遇到了同样的问题。使用sudo pecl install -f xdebug-2.9.8 将 Xdebug 降级到 2.9.8 修复问题 谢谢,这刚刚解决了我的问题! 谢谢你是最棒的???? @ThéoAttali 我认为你应该把它变成一个答案 这适用于 PHP 7.4 和 xdebug 3 【参考方案1】:

出现此错误是因为新的 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(或任何你用作模式的东西)

关注this issue 了解其他解决方案的更新

【讨论】:

这应该是公认的答案 - 这节省了我数小时的头撞墙时间。 对我来说,修复是使用lando在我的docker容器中将xdebug设置为false,但xdebug问题是我的原因。【参考方案2】:

另一种解决方案可能是更新到似乎可以与 XDEBUG 3 一起使用的 PHP 7.4

【讨论】:

【参考方案3】:

除了罗马的答案(应该是公认的答案)。对于选项 1,请在安装旧版本之前执行此步骤 https://howtoinstall.co/en/ubuntu/xenial/php-xdebug?action=remove

【讨论】:

以上是关于致命错误:方法 class@anonymous::__toString() 在作曲家安装后不得抛出异常的主要内容,如果未能解决你的问题,请参考以下文章

使命召唤14致命错误怎么解决?

电脑开机出现致命错误,怎么办?

PHPUnit 显示抛出致命错误异常的传递方法

致命错误:未捕获的错误:调用未定义的方法 stdClass::option();

Play框架下处理致命错误的正确方法

致命错误:在 joomla 3 中调用未定义的方法 JController::getInstance()