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

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

Open
klonos opened this issue Oct 12, 2021 · 3 comments

Comments

@klonos
Copy link
Member

klonos commented Oct 12, 2021

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
Copy link
Member Author

klonos commented Oct 12, 2021

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
Copy link
Member Author

klonos commented Oct 12, 2021

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
Copy link
Member Author

klonos commented Oct 12, 2021

@quicksketch @serundeputy thoughts on the above? ^^

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

No branches or pull requests

1 participant