backdrop-contrib / backdrop-drush-extension

A set of commands and boot class for Drush and Backdrop CMS.
GNU General Public License v2.0
13 stars 18 forks source link

php5: Argument 1 passed to drush_chalk() must be an instance of string, string given #248

Open klonos opened 2 years ago

klonos commented 2 years ago

The following error is thrown when trying to run drush en devel devel_generate -y in php 5.6.40:

Argument 1 passed to drush_chalk() must be an instance of string, string given,
called in /var/www/.drush/commands/pm/backdrop_pm_enable.drush.inc
on line 62 and defined output.inc:18                                                           [error]
E_RECOVERABLE_ERROR encountered; aborting.
To ignore recoverable errors, run again with --no-halt-on-error                                [error]
Drush command terminated abnormally due to an unrecoverable error. 

The same command works w/o throwing any errors in php 7.0+.

klonos commented 2 years ago

The code being mentioned in the error is this:

  $projects_list = implode(', ', $projects);
  $projects_list = drush_chalk($projects_list, '1m');

...trying to enable one module at a time doesn't make any difference.

klonos commented 2 years ago

The problem seems to be with typehinting. See: https://stackoverflow.com/questions/4103480/how-to-resolve-must-be-an-instance-of-string-string-given-prior-to-php-7

Prior to PHP 7 type hinting can only be used to force the types of objects and arrays. Scalar types are not type-hintable. In this case an object of the class string is expected, but you're giving it a (scalar) string. The error message may be funny, but it's not supposed to work to begin with. Given the dynamic typing system, this actually makes some sort of perverted sense.

http://php.net/manual/en/language.oop5.typehinting.php

Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn't supported.

So we basically need to decide if we'll be supporting php5 (in which case the type hinting should be removed from the drush_chalk() function), or leave things as they are and clearly state that things may not work properly if you are using php5.

klonos commented 2 years ago

@quicksketch @serundeputy thoughts on the above? ^^