Score:0

Drush fatal error with Declaration of Drupal\Core\Logger\LoggerChannel::log

in flag

When I run any drush command or even just drush I get the fatal error:

Fatal error: Declaration of Drupal\Core\Logger\LoggerChannel::log($level, $message, array $context = []) must be compatible with Psr\Log\LoggerTrait::log($level, Stringable|string $message, array $context = []): void in /core/lib/Drupal/Core/Logger/LoggerChannel.php on line 94

I updated drupal with composer to 9.5 and I'm running PHP 8.1. Here is my composer.json requirements:

    "require": {
        "composer/installers": "^1.9",
        "drupal/bootstrap": "^3.24",
        "drupal/captcha": "^1.2",
        "drupal/core-composer-scaffold": "^9.0.0",
        "drupal/core-project-message": "^9.0.0",
        "drupal/core-recommended": "^9.5",
        "drupal/core-vendor-hardening": "^8.8",
        "drupal/feeds": "^3.0@beta",
        "drupal/feeds_ex": "^1.0@alpha",
        "drupal/field_formatter": "^3.0@RC",
        "drupal/google_tag": "^1.5",
        "drupal/gtranslate": "^1.14",
        "drupal/honeypot": "^2.0",
        "drupal/image_popup": "^2.0",
        "drupal/mailsystem": "^4.3",
        "drupal/masquerade": "^2.0@RC",
        "drupal/menu_block": "^1.8",
        "drupal/metatag": "^1.19",
        "drupal/page_manager": "^4.0@beta",
        "drupal/paragraphs": "^1.13",
        "drupal/pathauto": "^1.9",
        "drupal/recaptcha": "^3.0",
        "drupal/recaptcha_element": "^1.0",
        "drupal/redirect": "^1.7",
        "drupal/schema_metatag": "^2.3",
        "drupal/sendgrid_integration": "^2.0@beta",
        "drupal/smtp": "^1.0",
        "drupal/twig_tweak": "^3.1",
        "drupal/views_bootstrap": "^4.3",
        "drupal/webform": "^6.1",
        "drupal/webform_spam_words": "^2.0",
        "drupal/webform_validation": "^2.0@alpha",
        "drupal/yoast_seo": "^2.0@alpha",
        "drush/drush": "^11.4",
        "google/recaptcha": "^1.2"
    },

Here are the plugins:

    "config": {
        "sort-packages": true,
        "allow-plugins": {
            "composer/installers": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "drupal/core-vendor-hardening": true,
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    },

I can't run any drush command and I get the following error if I go to my site:

Fatal error: Declaration of Drupal\dblog\Logger\DbLog::emergency($message, array $context = []) must be compatible with Psr\Log\LoggerInterface::emergency(Stringable|string $message, array $context = []): void in /core/lib/Drupal/Core/Logger/RfcLoggerTrait.php on line 20

Any suggestions on how to proceed?

EDIT* Additional Info:

PHP Version: 8.1.13

Drupal Core installed packages (from composer show -i):

drupal/core                                    9.5.0        
drupal/core-composer-scaffold                  9.4.9        
drupal/core-dev                                9.4.9       
drupal/core-project-message                    9.4.9 
drupal/core-recommended                        9.5.0  
drupal/core-vendor-hardening                   8.9.20       
id flag
Show us the plugins section of composer.json.
in flag
@cilefen Done. I also tried running php code sniffer. I got no errors in my modules. But I got a bunch of errors in core. Why would there be php 8 errors in core?
id flag
Absent any technical information at all about what you did with php code sniffer it is not possible to comment on that matter. The error you are reporting in the question is the kind of thing that could happen if there is an opcache problem or in some cases, two installs of Drupal, which has happened if the composer/installers plugin is disabled. What is the specific PHP version? What are the actual versions of the `drupal-core*` projects?
in flag
@cilefen See the edit
id flag
There is a comment on this other, current question which may be helpful: https://drupal.stackexchange.com/questions/314074/service-has-a-dependency-on-a-non-existent-service-error-when-upgrading-drupal?noredirect=1#comment401289_314074
in flag
@cilefen Truncating cache tables did nothing to fix the error.
id flag
It’s time for you to look at each of those classes to figure out why they are incongruent and to make sure there are not duplicates of any. Providing the entire composer.json file may help you get an answer but at this stage more information is needed.
in flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/141357/discussion-between-alxvallejo-and-cilefen).
Score:0
id flag

We discovered in chat that the reason this occurred is because there is a custom module installing its own Composer dependencies which clash with the ones loaded by Drupal.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.