0

I'm using PHP 8.1.2-1ubuntu2.14, Drush 8.4.12 (latest), and Drupal 7.98 (not yet updated).

I'm having a problem with a Drush command which uses Google APIs, Google Auth, and Google services. I get the following error.

PHP Fatal error: Declaration of Monolog\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = []) in /home/eliosh/PhpstormProjects/Mega7/sources/vendor/monolog/monolog/src/Monolog/Logger.php on line 681
Drush command terminated abnormally due to an unrecoverable error.
Error: Declaration of Monolog\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = []) in /home/eliosh/PhpstormProjects/Mega7/sources/vendor/monolog/monolog/src/Monolog/Logger.php, line 681

Following this comment in the monolog repo, I've added the following code before the call to the "problematic" function.

var_dump(class_exists('Psr\Log\LoggerInterface'), (new \ReflectionClass('Psr\Log\LoggerInterface'))->getFileName() ); 

The output is the following

bool(false) string(71) "phar:///usr/local/bin/drush8/vendor/psr/log/Psr/Log/LoggerInterface.php" 

This is the output of composer show.

composer/ca-bundle 1.4.0 Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle. dg/twitter-php v3.8 Small and easy Twitter library for PHP domnikl/statsd 2.10.0 a PHP client for statsd donatj/simplecalendar v0.6.2 A light, easy to use calendar rendering library exads/exads-api-client-php v1.3.1 Exads API client fastglass/sendgrid 2.0.6 This library allows you to send emails through SendGrid using PHP and Guzzle 6.x. firebase/php-jwt v6.10.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. geoip2/geoip2 v2.13.0 MaxMind GeoIP2 PHP API giggsey/libphonenumber-for-php 7.7.5 PHP Port of Google's libphonenumber giggsey/locale 1.9 Locale functions required by libphonenumber-for-php google/apiclient v2.15.3 Client library for Google APIs google/apiclient-services v0.331.0 Client library for Google APIs google/auth v1.34.0 Google Auth Library for PHP guzzlehttp/guzzle 7.8.1 Guzzle is a PHP HTTP client library guzzlehttp/promises 2.0.2 Guzzle promises library guzzlehttp/psr7 2.6.2 PSR-7 message implementation that also provides common utility methods intervention/image 2.7.2 Image handling and manipulation library with support for Laravel integration james-heinrich/getid3 v1.9.23 PHP script that extracts useful information from popular multimedia file formats jean85/pretty-package-versions 2.0.5 A library to get pretty versions strings of installed dependencies jenssegers/imagehash v0.9.0 Perceptual image hashing for PHP maxmind-db/reader v1.11.1 MaxMind DB Reader API maxmind/web-service-common v0.9.0 Internal MaxMind Web Service API mongodb/mongodb 1.11.0 MongoDB driver library monolog/monolog 3.5.0 Sends your logs to files, sockets, inboxes, databases and various web services paragonie/constant_time_encoding v2.6.3 Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16) paragonie/random_compat v9.99.100 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7 phpseclib/phpseclib 3.0.35 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc. psr/cache 3.0.0 Common interface for caching libraries psr/http-client 1.0.3 Common interface for HTTP clients psr/http-factory 1.0.2 Common interfaces for PSR-7 HTTP message factories psr/http-message 2.0 Common interface for HTTP messages psr/log 3.0.0 Common interface for logging libraries ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. starkbank/ecdsa 0.0.4 fast openSSL-compatible implementation of the Elliptic Curve Digital Signature Algorithm (ECDSA) symfony/deprecation-contracts v3.4.0 A generic function and convention to trigger deprecation notices symfony/polyfill-php80 v1.28.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions 

This is the output of composer show -p.

composer 2.6.2 Composer package composer-plugin-api 2.6.0 The Composer Plugin API composer-runtime-api 2.2.2 The Composer Runtime API ext-apcu 5.1.21 The apcu PHP extension ext-bcmath 8.1.2 The bcmath PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-calendar 8.1.2 The calendar PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-ctype 8.1.2 The ctype PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-curl 8.1.2 The curl PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-date 8.1.2 The date PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-dom 20031129 The dom PHP extension ext-exif 8.1.2 The exif PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-ffi 8.1.2 The FFI PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-fileinfo 8.1.2 The fileinfo PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-filter 8.1.2 The filter PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-ftp 8.1.2 The ftp PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-gd 8.1.2 The gd PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-gettext 8.1.2 The gettext PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-gmp 8.1.2 The gmp PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-hash 8.1.2 The hash PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-iconv 8.1.2 The iconv PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-igbinary 3.2.6 The igbinary PHP extension ext-imagick 3.6.0 The imagick PHP extension ext-json 8.1.2 The json PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-libxml 8.1.2 The libxml PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-mbstring 8.1.2 The mbstring PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-memcached 3.1.5 The memcached PHP extension ext-mongodb 1.12.0 The mongodb PHP extension ext-msgpack 2.2.0RC1 The msgpack PHP extension ext-mysqli 8.1.2 The mysqli PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-mysqlnd 0 The mysqlnd PHP extension (actual version: mysqlnd 8.1.2-1ubuntu2.14) ext-openssl 8.1.2 The openssl PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-pcntl 8.1.2 The pcntl PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-pcre 8.1.2 The pcre PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-pdo 8.1.2 The PDO PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-pdo_mysql 8.1.2 The pdo_mysql PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-pdo_sqlite 8.1.2 The pdo_sqlite PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-pdo_sqlsrv 5.11.0 The pdo_sqlsrv PHP extension ext-phar 8.1.2 The Phar PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-phash 0.9.6 The pHash PHP extension ext-posix 8.1.2 The posix PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-readline 8.1.2 The readline PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-redis 5.3.5 The redis PHP extension ext-reflection 8.1.2 The Reflection PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-session 8.1.2 The session PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-shmop 8.1.2 The shmop PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-simplexml 8.1.2 The SimpleXML PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-sockets 8.1.2 The sockets PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-sodium 8.1.2 The sodium PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-spl 8.1.2 The SPL PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-sqlite3 8.1.2 The sqlite3 PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-sqlsrv 5.11.0 The sqlsrv PHP extension ext-sysvmsg 8.1.2 The sysvmsg PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-sysvsem 8.1.2 The sysvsem PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-sysvshm 8.1.2 The sysvshm PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-tokenizer 8.1.2 The tokenizer PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-uploadprogress 2.0.2 The uploadprogress PHP extension ext-xdebug 3.1.2 The xdebug PHP extension ext-xml 8.1.2 The xml PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-xmlreader 8.1.2 The xmlreader PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-xmlwriter 8.1.2 The xmlwriter PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-xsl 8.1.2 The xsl PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-zend-opcache 8.1.2 The Zend OPcache PHP extension (actual version: 8.1.2-1ubuntu2.14) ext-zip 1.19.5 The zip PHP extension ext-zlib 8.1.2 The zlib PHP extension (actual version: 8.1.2-1ubuntu2.14) lib-curl 7.81.0 The curl library lib-curl-libssh 0.9.6 curl libssh version lib-curl-openssl 3.0.2 curl OpenSSL version (3.0.2) lib-curl-zlib 1.2.11 curl zlib version lib-date-timelib 2021.11 date timelib version lib-date-zoneinfo 0 zoneinfo ("Olson") database for date lib-fileinfo-libmagic 540 fileinfo libmagic version lib-gd 2.3.0 The gd library lib-gmp 6.2.1 The gmp library lib-iconv 2.35 The iconv library lib-imagick-imagemagick 6.9.11.60 The imagick-imagemagick library lib-libsodium 1.0.18 The libsodium library lib-libxml 2.9.13 libxml library version lib-libxslt 1.1.34 The libxslt library lib-libxslt-libxml 2.9.13 libxml version libxslt is compiled against lib-mbstring-libmbfl 1.3.2 mbstring libmbfl version lib-mbstring-oniguruma 6.9.7 mbstring oniguruma version lib-memcached-libmemcached 1.0.18 libmemcached version lib-mongodb-libbson 1.20.0 libbson version of mongodb lib-mongodb-libmongoc 1.20.0 libmongoc version of mongodb lib-openssl 3.0.2 OpenSSL 3.0.2 15 Mar 2022 lib-pcre 10.39 The pcre library lib-pcre-unicode 14.0.0 PCRE Unicode version support lib-pdo_sqlite-sqlite 3.37.2 The pdo_sqlite-sqlite library lib-sqlite3-sqlite 3.37.2 The sqlite3-sqlite library lib-zip-libzip 1.7.3 The zip-libzip library lib-zlib 1.2.11 The zlib library php 8.1.2 The PHP interpreter php-64bit 8.1.2 The PHP interpreter, 64bit php-ipv6 8.1.2 The PHP interpreter, with IPv6 support 

How can I solve this problem?

9
  • 1
    You have a conflict with vendor code loaded by PHPStorm, obviously. Commented Jan 17, 2024 at 13:46
  • 1
    This error happens also outside phpstorm, on the remote server. As you can see, the problem is with the implementation of LoggerInterface in drush 8 Commented Jan 17, 2024 at 14:28
  • As perhaps you can see, Drush is conflicting with PhpstormProjects/Mega7/sources/vendor/monolog/monolog/src/Monolog/Logger.php. Commented Jan 17, 2024 at 14:37
  • @cilefen – I think this is just a folder name, nothing to do with Pstorm. I think this is just a PHP 8.1 compat issue. Commented Jan 17, 2024 at 23:31
  • 1
    How is Drush installed there? In what way is Composer involved with this question about a Drupal 7 site? Commented Jan 18, 2024 at 0:04

2 Answers 2

2

The problem was that, with Drupal 7, you don't need to add drush as a requirement via composer.

The solution to this problem is to require drush via composer, but forcing the version "<9", the only compatible with drupal 7.

In this way, composer downgraded "psr/log" and "monolog/monolog" packages and we can continue using global drush 8

Thanks a lot to everyone.

1

Global Drush installs are not supported when the codebase auto loads with Composer and this is the reason. Install and run Drush as documented.

3
  • Drush 12 does not work with Drupal 7 Commented Jan 18, 2024 at 14:23
  • That's well understood. Can you not install Drush 8 via Composer into this site? If not you may be in a situation where vendor dependencies you installed into the codebase, in a PHP 8.1 setting, cannot be installed alongside Drush 8, and you may be forced to look for lower versions of those dependencies. Commented Jan 18, 2024 at 15:56
  • You are right. Adding "drush/drush": "<9" to composer.json, downgraded psr/log and monolog to be all compatible. Commented Jan 19, 2024 at 9:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.