2

So I've just installed drush 11.2.0 with Drupal 9.4.6 and the first time I executed drush si, I got this error.

PHP Fatal error: Declaration of Drush\Application::setLogger(Psr\Log\LoggerInterface $logger) must be compatible with Psr\Log\LoggerAwareInterface::setLogger(Psr\Log\LoggerInterface $logger): void in /app/vendor/drush/drush/src/Application.php on line 22

What can I do to fix this issue?

If it matters, I am using Lando.

7
  • How did you install Drush? Exactly how did you execute Drush?
    – mona lisa
    Commented Sep 23, 2022 at 14:14
  • lando composer require drush/drush and lando drush si ....
    – Kartagis
    Commented Sep 23, 2022 at 14:19
  • We would have to see enough of composer.json to have any idea how to advise here.
    – mona lisa
    Commented Sep 23, 2022 at 14:47
  • Which part do you want to see?
    – Kartagis
    Commented Sep 23, 2022 at 14:48
  • We need the part where we could figure out why drush/drush is incompatible with the installed version of psr/log. Line 22 of src/Application.php in Drush isn't a function declaration but a use statement. Can you confirm that src/Application.php looks as it should, which is: github.com/drush-ops/drush/blob/11.2.0/src/Application.php
    – mona lisa
    Commented Sep 23, 2022 at 15:04

4 Answers 4

2

I faced the issue too.

It seems that it's caused by the difference between the version of the psr/log package you have in your project and the one in the global vendor of your computer. I explain.

On Drupal 9.4, the dependency version for psr/log is ~1.1.4. When you install Drush globally on your machine with Composer, it'll install psr/log on version 3.0.0. And if you look at this MR (https://github.com/php-fig/log/pull/77) of psr/log package, you'll see that the signature of the function changed on the last version so it throws the exception.

The solution is to use an alias for drush binary directly from the project's dependencies, waiting for Drupal 10 and its updated dependencies.

Hope it answers your issue !

1

This issue also caught me. But none of the solutions worked for me. I was using global drush for all my projects, I finally uninstalled drush globally and installed it per project. In combination with DirEnv. Now everything is smooth!

1

You could also pin the Drush version in the composer.json by doing the following,

  1. Open your composer.json file.
  2. In the required section add or change "drush/drush": "^10.0".
  3. From the terminal run "composer update".
0

The solution is: go to your global composer.json and add

"psr/log": "~1.1"

then run composer global update -W

1
  • I added this to my drush composer.json and now I get this error instead: Error: Call to undefined function Drush\Commands\core\drush_cache_clear_all()
    – Matt B
    Commented Jan 3, 2023 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.