You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Symfony 2.8执行Composer操作时出现类型错误求助

解决Symfony 2.8 + PHP 5.6下Composer脚本的Process TypeError问题

在PHP 5.6.39环境部署Symfony 2.8项目时,执行composer install或composer update会触发TypeError:Symfony\Component\Process\Process::__construct()的第1个参数$command必须为array类型,却传入string。错误根源在Sensio\Bundle\DistributionBundle\Composer\ScriptHandler的buildBootstrap执行环节。

项目composer.json配置

{    
    "name": "symfony/framework-standard-edition",    
    "license": "MIT",    
    "type": "project",    
    "description": "The \"Symfony Standard Edition\" distribution",    
    "autoload": {        
        "psr-0": { "": "src/" }    
    },    
    "config": {        
        "bin-dir": "bin",        
        "platform": {            
            "php": "5.6.39"        
        }    
    },    
    "require": {        
        "php": "5.6.39",        
        "symfony/symfony": "2.8.*",        
        "doctrine/orm": "2.*",        
        "doctrine/doctrine-bundle": "1.2.*",        
        "twig/extensions": "1.0.*",        
        "symfony/assetic-bundle": "2.3.*",        
        "symfony/swiftmailer-bundle": "2.3.*",        
        "symfony/monolog-bundle": "2.3.*",        
        "sensio/distribution-bundle": "^3.0",        
        "sensio/framework-extra-bundle": "2.3.*",        
        "sensio/generator-bundle": "2.3.*",        
        "incenteev/composer-parameter-handler": "~2.0",        
        "jms/security-extra-bundle": "1.5.1",        
        "doctrine/doctrine-fixtures-bundle": "2.3.*",        
        "bmatzner/modernizr-bundle": "~2.7",        
        "bmatzner/jquery-bundle": "~1.9",        
        "bmatzner/foundation-bundle": "~5.3",        
        "bmatzner/fontawesome-bundle": "4.*",        
        "knplabs/knp-snappy-bundle": "~1.4",        
        "sendinblue/sendinblue-api-bundle": "^2.0",        
        "ob/highcharts-bundle": "1.*",        
        "h4cc/wkhtmltopdf-amd64": "^0.12.3",        
        "h4cc/wkhtmltoimage-amd64": "^0.12.3",        
        "egeloen/google-map-bundle": "^2.2",        
        "liuggio/excelbundle": "^2.1",        
        "phpoffice/phpspreadsheet": "^1.6",        
        "phpoffice/phpword": "^0.17.0"    
    },    
    "scripts": {        
        "post-install-cmd": [            
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"        
        ],        
        "post-update-cmd": [            
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",            
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"        
        ]    
    },    
    "minimum-stability": "stable",    
    "extra": {        
        "symfony-app-dir": "app",        
        "symfony-web-dir": "web",        
        "symfony-assets-install": "symlink",        
        "incenteev-parameters": {            
            "file": "app/config/parameters.yml"        
        },        
        "branch-alias": {            
            "dev-master": "2.8-dev"        
        }    
    }
}

完整错误栈

> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> PHP Fatal error:  Uncaught TypeError: Symfony\Component\Process\Process::__construct(): Argument #1 ($command) must be of type array, string given, called in /home/lucas/IBS/ibs-extanet/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Composer/ScriptHandler.php on line 455 and defined in /usr/share/php/Symfony/Component/Process/Process.php:143
> Stack trace:
> #0 /home/lucas/IBS/ibs-extanet/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Composer/ScriptHandler.php(455): Symfony\Component\Process\Process->__construct()
> #1 /home/lucas/IBS/ibs-extanet/vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Composer/ScriptHandler.php(82): Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::executeBuildBootstrap()
> #2 /usr/share/php/Composer/EventDispatcher/EventDispatcher.php(389): Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap()
> #3 /usr/share/php/Composer/EventDispatcher/EventDispatcher.php(238): Composer\EventDispatcher\EventDispatcher->executeEventPhpScript()
> #4 /usr/share/php/Composer/EventDispatcher/EventDispatcher.php(119): Composer\EventDispatcher\EventDispatcher->doDispatch()
> #5 /usr/share/php/Composer/Installer.php(372): Composer\EventDispatcher\EventDispatcher->dispatchScript()
> #6 /usr/share/php/Composer/Command/UpdateCommand.php(248): Composer\Installer->run()
> #7 /usr/share/php/Symfony/Component/Console/Command/Command.php(298): Composer\Command\UpdateCommand->execute()
> #8 /usr/share/php/Symfony/Component/Console/Application.php(1015): Symfony\Component\Console\Command\Command->run()
> #9 /usr/share/php/Symfony/Component/Console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
> #10 /usr/share/php/Composer/Console/Application.php(336): Symfony\Component\Console\Application->doRun()
> #11 /usr/share/php/Symfony/Component/Console/Application.php(171): Composer\Console\Application->doRun()
> #12 /usr/share/php/Composer/Console/Application.php(131): Symfony\Component\Console\Application->run()
> #13 /usr/bin/composer(84): Composer\Console\Application->run()
> #14 {main}
> thrown in /usr/share/php/Symfony/Component/Process/Process.php on line 143

解决方案

1. 锁定sensio/distribution-bundle的兼容版本

当前composer.json中sensio/distribution-bundle使用^3.0版本范围,会拉取3.x系列的最新版本,但部分高版本3.x与Symfony 2.8的Process组件不兼容(Symfony 2.8的Process构造函数允许传入string,而高版本的sensio脚本错误地传入了string给要求array的Process版本)。将版本锁定为3.0.29(3.x系列中与Symfony 2.8完全兼容的稳定版):

修改composer.json的require部分:

"sensio/distribution-bundle": "3.0.29",

2. 清理缓存并重新执行安装

删除现有依赖目录和锁文件,确保重新拉取正确版本的依赖:

rm -rf vendor composer.lock
composer install

3. 临时禁用脚本(调试用)

如果需要先完成依赖安装再处理脚本,可使用--no-scripts跳过post-install/post-update脚本:

composer install --no-scripts

之后手动执行必要的初始化操作:

php bin/symfony_requirements
php app/console cache:clear --env=prod
php app/console assets:install web --symlink

内容的提问来源于stack exchange,提问作者CatCake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 18:42:05