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

Declaration of Monolog\Logger::emergency void must be compatible (again) #1808

Open
killua-eu opened this issue May 20, 2023 · 10 comments
Open
Labels

Comments

@killua-eu
Copy link

killua-eu commented May 20, 2023

Monolog version 3

I'm getting a similar/same issue as described in #1764.

I'm pulling my dependencies with

  "require": {
    "php": "^8.2",
    "ext-apcu": "*",
    "ext-bcmath": "*",
    "ext-curl": "*",
    "ext-gd": "*",
    "ext-gmp": "*",
    "ext-imap": "*",
    "ext-json": "*",
    "ext-mbstring": "*",
    "ext-mysqli": "*",
    "ext-readline": "*",
    "ext-soap": "*",
    "ext-xml": "*",
    "ext-zip": "*",
    "casbin/database-adapter": "^1",
    "facile-it/php-openid-client": "dev-master",
    "geocoder-php/geoip2-provider": "^4",
    "google/apiclient": "^2",
    "grasmash/yaml-expander": "^3",
    "guzzlehttp/psr7": "^2.5",
    "http-interop/http-factory-guzzle": "^1",
    "league/flysystem": "^3",
    "linfo/linfo": "^4",
    "middlewares/csp": "^3",
    "middlewares/trailing-slash": "^2",
    "mohammad-waleed/keycloak-admin-client": "^0",
    "monolog/monolog": "^3",
    "nesbot/carbon": "^2",
    "nyholm/psr7": "^1",
    "opis/json-schema": "^2",
    "paragonie/csp-builder": "^2.8",
    "php-di/php-di": "^7",
    "php-http/guzzle7-adapter": "^1",
    "psr/http-message": "^1",
    "phpfastcache/phpfastcache": "^9",
    "ramsey/uuid": "^4",
    "respect/validation": "^2",
    "sabre/event": "^5",
    "selective/transformer": "^1",
    "slim/http": "^1",
    "slim/slim": "^4",
    "symfony/config": "^6",
    "symfony/mailer": "^6",
    "symfony/yaml": "^6",
    "thingengineer/mysqli-database-class": "dev-master#42116651a88b57b03fd967bc57dd38f5094565d9",
    "vaizard/glued-lib": "dev-main",
    "vlucas/phpdotenv": "^5",
    "voku/anti-xss": "^4",
    "web-token/jwt-framework": "^3",
    "zeuxisoo/slim-whoops": "^0.7"
  },

The platform is as follows:

root@g:/var/www/html/glued-core# composer show -p
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? 
composer               2.5.5    Composer package
composer-plugin-api    2.3.0    The Composer Plugin API
composer-runtime-api   2.2.2    The Composer Runtime API
ext-apcu               5.1.22   The apcu PHP extension
ext-bcmath             8.2.6    The bcmath PHP extension
ext-calendar           8.2.6    The calendar PHP extension
ext-ctype              8.2.6    The ctype PHP extension
ext-curl               8.2.6    The curl PHP extension
ext-date               8.2.6    The date PHP extension
ext-dom                20031129 The dom PHP extension
ext-exif               8.2.6    The exif PHP extension
ext-ffi                8.2.6    The FFI PHP extension
ext-fileinfo           8.2.6    The fileinfo PHP extension
ext-filter             8.2.6    The filter PHP extension
ext-ftp                8.2.6    The ftp PHP extension
ext-gd                 8.2.6    The gd PHP extension
ext-gettext            8.2.6    The gettext PHP extension
ext-gmp                8.2.6    The gmp PHP extension
ext-hash               8.2.6    The hash PHP extension
ext-iconv              8.2.6    The iconv PHP extension
ext-imap               8.2.6    The imap PHP extension
ext-intl               8.2.6    The intl PHP extension
ext-json               8.2.6    The json PHP extension
ext-libxml             8.2.6    The libxml PHP extension
ext-mbstring           8.2.6    The mbstring PHP extension
ext-mysqli             8.2.6    The mysqli PHP extension
ext-mysqlnd            0        The mysqlnd PHP extension (actual version: mysqlnd 8.2.6)
ext-openssl            8.2.6    The openssl PHP extension
ext-pcntl              8.2.6    The pcntl PHP extension
ext-pcre               8.2.6    The pcre PHP extension
ext-pdo                8.2.6    The PDO PHP extension
ext-pdo_mysql          8.2.6    The pdo_mysql PHP extension
ext-phar               8.2.6    The Phar PHP extension
ext-posix              8.2.6    The posix PHP extension
ext-random             8.2.6    The random PHP extension
ext-readline           8.2.6    The readline PHP extension
ext-reflection         8.2.6    The Reflection PHP extension
ext-session            8.2.6    The session PHP extension
ext-shmop              8.2.6    The shmop PHP extension
ext-simplexml          8.2.6    The SimpleXML PHP extension
ext-soap               8.2.6    The soap PHP extension
ext-sockets            8.2.6    The sockets PHP extension
ext-sodium             8.2.6    The sodium PHP extension
ext-spl                8.2.6    The SPL PHP extension
ext-sysvmsg            8.2.6    The sysvmsg PHP extension
ext-sysvsem            8.2.6    The sysvsem PHP extension
ext-sysvshm            8.2.6    The sysvshm PHP extension
ext-tokenizer          8.2.6    The tokenizer PHP extension
ext-xml                8.2.6    The xml PHP extension
ext-xmlreader          8.2.6    The xmlreader PHP extension
ext-xmlwriter          8.2.6    The xmlwriter PHP extension
ext-xsl                8.2.6    The xsl PHP extension
ext-zend-opcache       8.2.6    The Zend OPcache PHP extension
ext-zip                1.21.1   The zip PHP extension
ext-zlib               8.2.6    The zlib PHP extension
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       2022.07  date timelib version
lib-date-zoneinfo      0        zoneinfo ("Olson") database for date
lib-fileinfo-libmagic  540      fileinfo libmagic version
lib-gd                 2.3.3    The gd library
lib-gmp                6.2.1    The gmp library
lib-iconv              2.35     The iconv library
lib-icu                70.1     The ICU unicode and globalization support library
lib-icu-cldr           40       ICU CLDR project version
lib-icu-unicode        14.0.0   ICU unicode version
lib-icu-zoneinfo       2023.3   zoneinfo ("Olson") database for icu
lib-libsodium          1.0.18   The libsodium library
lib-libxml             2.9.14   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-openssl            3.0.2    OpenSSL 3.0.2 15 Mar 2022
lib-pcre               10.40    The pcre library
lib-pcre-unicode       14.0.0   PCRE Unicode version support
lib-zip-libzip         1.7.3    The zip-libzip library
lib-zlib               1.2.11   The zlib library
php                    8.2.6    The PHP interpreter
php-64bit              8.2.6    The PHP interpreter, 64bit
php-ipv6               8.2.6    The PHP interpreter, with IPv6 support

I get bitten by this when running some composer hooks. I tracked down the problem to $array = Yaml::parse($yaml, Yaml::PARSE_CONSTANT); (Symfony Yaml class). Interestingly, the composer hooks never pull in Monolog, but it still somehow gets pulled in (I'm not logging anything, and where a loggerinterface is required to instantiate a class, I use Psr\Log\NullLogger()).

Honestly I'm at loss on how to further debug/fix this. I don't know how Monolog gets pulled in. It seems that Symfony errors out on something and somehow ends up using Monolog while at the same time (maybe) throwing its on LoggerInterface implementation that is part of the Symfony\Console dependency. I'll appreciate any ideas or pointers.

@killua-eu killua-eu added the Bug label May 20, 2023
@galtsevt
Copy link

galtsevt commented May 31, 2023

I ran into a probable problem, my hosting has php extension installed https://github.com/jbboehr/php-psr
LoggerInterface corresponds to https://www.php-fig.org/psr/psr-3/ .
But monolog uses composer package https://github.com/php-fig/log where LoggerInterface has other input and output.

@Seldaek Seldaek added Support and removed Bug labels Jun 20, 2023
@Seldaek
Copy link
Owner

Seldaek commented Jun 20, 2023

This isn't a monolog issue, but a dependency issue. Somehow you must have an outdated psr/log loaded somewhere. You gotta figure out why that is.

@stof
Copy link
Contributor

stof commented Jun 20, 2023

The issue with the php-psr extension is that it does not account for the fact that PSR packages have multiple versions.

The fix is to disable the extension. This extension is known to be the root cause of hundreds of similar issues, and there is no benefit of using it vs using the userland package IMO (if you are concerned about the impact of autoloading, use the preload feature of PHP instead)

@killua-eu
Copy link
Author

Hi @Seldaek , is there some place else but vendor/psr/log where a wrong depencency could land?
The code that causes the problem is loading https://github.com/grasmash/yaml-expander (upon instantiation, it requires to set a logger, which I'm setting as $ye = new YamlExpander(new Logger('null_logger', [new NullHandler()]));, i'm also explicitly using use Monolog\Logger; and use Monolog\Handler\NullHandler;.
@stof , I don't have the php-psr package installed.

@Seldaek
Copy link
Owner

Seldaek commented Jul 1, 2023

You can add var_dump(class_exists('Psr\Log\LoggerInterface'), (new \ReflectionClass('Psr\Log\LoggerInterface'))->getFileName()); above your new YamlExpander line, hopefully that will show you where it came from at least.

@natanael-aguiar
Copy link

I have the same problem as my colleague, any solution for this?

@stof
Copy link
Contributor

stof commented Dec 4, 2023

Well, as he did not answer the question of @Seldaek, this would be a good start.

@bahaa-almahamid
Copy link

bahaa-almahamid commented Dec 13, 2023

as a hot fix, downgrade monolog to 2.9, because the latest version still produce this error

@wj-ed
Copy link

wj-ed commented Jan 12, 2024

Hi, I had the same problem on an internal project. In my case, following @Seldaek suggestion

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

at the top of problematic class and get

bool(false)
string(67) "phar:///usr/bin/composer/vendor/psr/log/Psr/Log/LoggerInterface.php"

The problem seems to come from psr/log version of composer, as mention in composer/composer#11246 (comment)

I will explore the suggestion of splitting script off into its own process/command that I can call as a script.

@wilfried-ed
Copy link

I confirm that using intermediate bash script to run php command bypass this issue.

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

No branches or pull requests

8 participants