Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count(): Parameter must be an array or an object that implements Countable #3226

Closed
Chi-teck opened this issue Dec 9, 2017 · 22 comments
Closed
Labels

Comments

@Chi-teck
Copy link
Collaborator

Chi-teck commented Dec 9, 2017

This only happens on PHP 7.2

$ php drush.php st
count(): Parameter must be an array or an object that implements Countable   [warning]
Table.php:789
count(): Parameter must be an array or an object that implements Countable   [warning]
Table.php:789
count(): Parameter must be an array or an object that implements Countable   [warning]
Table.php:789
count(): Parameter must be an array or an object that implements Countable   [warning]
Table.php:789
count(): Parameter must be an array or an object that implements Countable   [warning]
Table.php:789
count(): Parameter must be an array or an object that implements Countable   [warning]
Table.php:789
count(): Parameter must be an array or an object that implements Countable   [warning]
Table.php:789
 PHP configuration      :  /etc/php/7.2/cli/php.ini 
 PHP OS                 :  Linux                    
 Drush script           :  /var/www/drush/drush.php 
 Drush version          :  8.1.16-dev               
 Drush temp directory   :  /tmp                     
 Drush configuration    :                           
 Drush alias files      :                             

pear/Console_Table#14

@Chi-teck Chi-teck added the drush8 label Dec 9, 2017
@anavarre
Copy link

Confirmed with Drush 9 RC1.

@Chi-teck
Copy link
Collaborator Author

@anavarre Are you sure? Drush 9 has no dependency on pear/console_table.

@anavarre
Copy link

No, I'm not. It happened when installing either the Lightning or Reservoir distro, not with vanilla Drupal 8.5.x - I honestly didn't dig deeper yet.

@anavarre
Copy link

anavarre commented Dec 12, 2017

BTW, is it on Drush to fix the issue? It seems to me it could be a core bug https://www.drupal.org/project/drupal/issues/2928846

@Chi-teck
Copy link
Collaborator Author

Chi-teck commented Dec 12, 2017

It is a general PHP 7.2 issue. count() function should not be used to count uncountable values anymore.
http://php.net/manual/en/migration72.incompatible.php#migration72.incompatible.warn-on-non-countable-types.

This particular warning comes from Pear Console Table package. I referenced related issue in the ticket description. That package does not seem actively maintained. Given it is just a single class, we could simply copy it to Drush 8 codebase.

@Ayesh
Copy link
Contributor

Ayesh commented Dec 18, 2017

A backtrace says the call is in includes/output.inc:303, and it doesn't look like we can fix/workaround this from Drush's side.

function _updateRowsCols($rowdata = null) {
   // ...
  $this->_max_cols = max($this->_max_cols, count($rowdata));
  // ...
}

Console_Table class is doing it wrong because it relies on the count() to function as an !empty() as well.
My 👍 to copy, fix, and keep the class ourselves. It's not like we can make significant changes (for example use a better library) at this 8.x age.

Alternately we could @silent() the parent caller. Feels dirty either way.

@weitzman
Copy link
Member

weitzman commented Jan 5, 2018

If someone wants to make a PR for drush8, that would be appreciated. Seems like @silent operator is better than copying the lib.

@Ayesh
Copy link
Contributor

Ayesh commented Jan 5, 2018

@weitzman - Please see #3292 with the @silent workaround. Some of the builds are failing for connectivity issues, but majority of them passed.

@gentleKun
Copy link

Hello,I met the same error,do you fix it out?

@greg-1-anderson
Copy link
Member

Is this fixed in pear/console_table 1.3.1 / Drush 8.1.16? Not sure what the resolution was, but that seemed to be my conclusion during light testing yesterday. Didn't see the message when running 8.1.16.

@Ayesh
Copy link
Contributor

Ayesh commented Mar 9, 2018 via email

@jameswilson
Copy link

Can confirm that running pear install Console_Table fixed this issue for me, which updated to the latest version 1.3.1

@binarycpu
Copy link

Using pear install Console_Table I was also updated to 1.3.1 but I unfortunately am still flooded with count() warnings. When installing drush 8 dev, I get version 8.0.2; where when installing drush 8 I get version 8.0.0. I think something is confused. Regardless, upgrading to drush 9 resolved all of the issues.

@darkdiesel
Copy link

drush 7 and php7.2 the same problem

@Chi-teck
Copy link
Collaborator Author

I think the PHP requirements in the documentation are not correct. Old Drush version are likely not compatible with PHP 7.2+.
https://docs.drush.org/en/master/install/#drupal-compatibility

fmiro added a commit to fmiro/docker-apache-drupal that referenced this issue Jun 6, 2019
Use Console_Table 1.3.1 instead of Console_Table 1.1.5 that comes by default with drush 6.7.0 version.
At https://github.com/drush-ops/drush/blob/6.x/includes/environment.inc Console_Table 1.1.5 is downloaded dynamically if it does not already exist in lib folder. So we download 1.3.1 first and rename it to 1.1.5 as a "trick" to make it work without any other change
pataquets added a commit to pataquets/docker-apache-drupal that referenced this issue Jun 12, 2019
@kenahoo
Copy link
Contributor

kenahoo commented Oct 1, 2019

I have Drush 7.4 and PHP 7.3.9, and I'm still seeing this issue. Console_Table is already upgraded to 1.3.1. What's the proper fix for this issue?

@Chi-teck
Copy link
Collaborator Author

Chi-teck commented Oct 1, 2019

@kenahoo Drush 7 is unsupported. Updating to Drush 8 will resolve the issue.

@kenahoo
Copy link
Contributor

kenahoo commented Oct 2, 2019

Thanks @Chi-teck , that indeed resolved it.

@chriscalip
Copy link

Error sighted. If drush is globally installed this can be fixed via:
composer global require pear/console_table

@relibar
Copy link

relibar commented Apr 10, 2020

Error sighted. If drush is globally installed this can be fixed via:
composer global require pear/console_table

That solved it! Thanks

@claudiu-cristea
Copy link
Member

claudiu-cristea commented Dec 10, 2020

For Drush 7 users. I've added this requirement in my project composer.json, cc @darkdiesel:

"pear/console_table": "v1.3.1 as v1.2.99"

@i-cristea
Copy link

For Drush 7 users. I've added this requirement in my project composer.json, cc @darkdiesel:

"pear/console_table": "v1.3.1 as v1.2.99"

For Drush 7, installed globally I added this in the ~/.composer/composer.json file, and then I runned 'composer update'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests