【问题标题】:Symfony 4 - Default value for parameters with a class type hint can only be NULLSymfony 4 - 具有类类型提示的参数的默认值只能为 NULL
【发布时间】:2018-05-10 10:20:30
【问题描述】:

我有一个与这里类似的问题:Symfony 4 : Default value for parameters with a class type can only be 但是当我启动作曲家命令时...:

executing script security-checker security:check [KO]
 [KO]
Script security-checker security:check returned with error code 255
!!  PHP Fatal error:  Default value for parameters with a class type hint can only be NULL in /xxx/vendor/symfony/console/Application.php on line 83
!!  
Script @auto-scripts was called via post-update-cmd
When I launched for example : php7 composer.phar update, because I had the same problem for others commands...

我不明白,因为我使用的是 7.1.8 PHP 版本...我用我的 PHP 7.1.8 安装了整个项目...:/

受影响的代码:

/**
     * @param string $name    The name of the application
     * @param string $version The version of the application
     */
    public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN') // Line affected HERE (line 83)
    {
        $this->name = $name;
        $this->version = $version; 
        $this->terminal = new Terminal();
        $this->defaultCommand = 'list';
    }

对我有什么想法?

非常感谢!

【问题讨论】:

  • 能否发布受影响的代码?
  • 没关系。受影响的行是(函数的)第一行。感谢您的帮助。
  • 你确定你在 PHP 7 上运行吗? Composer 可能使用与您的网络服务器不同的 PHP 版本。在命令行上运行php -v 会得到什么?
  • 我有一个别名 php7。当我运行我的别名“php7 -v”时,我得到这个: PHP 7.1.8 (cli) (built: Aug 17 2017 11:34:56) (NTS) Copyright (c) 1997-2017 The PHP Group Zend Engine v3 .1.0,版权所有 (c) 1998-2017 Zend Technologies
  • 哈,它也更改为 7.1.8... 但通常情况下,我想要带有 php 命令的 PHP 5.6。我在 Mamp 中暂时更改了此设置,以确保 CLI 也有 7.1.8 版本。

标签: php composer-php symfony4


【解决方案1】:

我不知道这样做是否可以...我在composer.json中替换了这一行:

 "security-checker security:check": "script"

作者:

 "security:check": "symfony-cmd"

我猜并希望命令是相同的。我不明白为什么。我遵循 Symfony 4 的官方文档,并且我拥有正确的 PHP 版本。 :/

我根本不知道... TT__TT

【讨论】:

    猜你喜欢
    • 2020-05-04
    • 2020-04-20
    • 2017-04-29
    • 1970-01-01
    • 2016-11-24
    • 2012-01-21
    • 2020-01-24
    • 1970-01-01
    • 2021-08-19
    相关资源
    最近更新 更多