如何修复 Drush 8 / PHP 7.2 警告“count():参数必须是数组...”

如何修复 Drush 8 / PHP 7.2 警告“count():参数必须是数组...”

我在 Ubuntu 16.04 上运行 LAMP。我安装了 drupal 7,并通过 Composer 版本 1.5.2 安装了 drush 8.1.3。我认为php7.2 导致错误正如在 Github 上讨论的那样,然而,即使我应用了推荐的修复方法,即将 pear/console_table 更新到最新版本此处指示,问题仍然存在。我也按照超级用户确信我已经最新版本的梨也安装了(没有安装 PHPunit)。并且,仅供参考,根据drush 安装文档在此处,我也对我的文件做了适当的更改.bashrc(如下)。

每当我运行时drush status都会收到以下错误:

count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
count(): Parameter must be an array or an object that implements     [warning]
Countable Table.php:789
PHP executable         :  /usr/bin/php                                 
PHP configuration      :  /etc/php/7.2/cli/php.ini                     
PHP OS                 :  Linux                                        
Drush script           :  /home/webdevusr/vendor/drush/drush/drush.php 
Drush version          :  8.1.13                                       
Drush temp directory   :  /tmp                                         
Drush configuration    :                                               
Drush alias files      :   

如果我执行drush sql-connect

Unable to load class Drush\Sql\Sql                                  [error]
Drush\Sql\SqlException: Unable to find a matching SQL Class. Drush   [error]
cannot find your database connection details. in
/home/webdevusr/vendor/drush/drush/commands/sql/sql.drush.inc:541
Stack trace:
#0
/home/webdevusr/vendor/drush/drush/commands/sql/sql.drush.inc(221):
drush_sql_get_class()
#1 /home/webdevusr/vendor/drush/drush/includes/command.inc(422):
drush_sql_connect()
#2 /home/webdevusr/vendor/drush/drush/includes/command.inc(231):
_drush_invoke_hooks(Array, Array)
#3 /home/webdevusr/vendor/drush/drush/includes/command.inc(199):
drush_command()
#4
/home/webdevusr/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67):
drush_dispatch(Array)
#5 /home/webdevusr/vendor/drush/drush/includes/preflight.inc(66):
Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#6 /home/webdevusr/vendor/drush/drush/drush.php(12): drush_main()
#7 {main}

我的文件内容~/.bashrc如下:

export PATH="$HOME/.composer/vendor/bin:$PATH"

export PATH=/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH

# Include Drush bash customizations.
if [ -f "/home/webdevusr/.drush/drush.bashrc" ] ; then
source /home/webdevusr/.drush/drush.bashrc
fi

# Include Drush completion.

if [ -f "/home/webdevusr/.drush/drush.complete.sh" ] ; then
source /home/webdevusr/.drush/drush.complete.sh
fi

# Include Drush prompt customizations.

if [ -f "/home/webdevusr/.drush/drush.prompt.sh" ] ; then
source /home/webdevusr/.drush/drush.prompt.sh
fi

drush cc all从我的 drupal 安装文件夹中执行的结果是:

No Drupal site found, only 'drush' cache was cleared. 

有人知道如何让 drush 适用于我的本地(LAMP)Drupal 7 安装吗?

答案1

在文件中.config/composer/vendor/pear/console_table/Table.php,我们可以看到所涉及的函数_updateRowsCols($rowdata = null)具有错误的签名,其参数被分配null为默认值 - 而不是可数

与其使用@运算符,因为它可能会忽略比预期更多的错误/警告,不如修复函数签名:

function _updateRowsCols($rowdata = []) {...}

... 和/或使用空合并运算符 ??在函数调用中安全地回退到一个空的(但可数的)数组:

$this->_max_cols = max($this->_max_cols, count($rowdata ?? []));

[编辑] 值得注意的是,该问题的修复pear/Console_Table已于 2017 年 10 月提交,而该问题是在 2018 年提出的。因此只需使用最新版本...无论如何,仅供参考,这里是使用三元运算符的代码修复,可能是为了向后兼容:

function _updateRowsCols($rowdata = null)
    {
        // Update maximum columns.
        $this->_max_cols = max($this->_max_cols, is_array($rowdata) ? count($rowdata) : 0);

        ...
    }

答案2

您可以编辑 .config/composer/vendor/pear/console_table/Table.php 或先在系统中查找该文件。使用您喜欢的编辑器打开它并编辑第 789 行。像这样将其静音:

@$this->_max_cols = max($this->_max_cols, count($rowdata));

你已准备好了。

相关内容