[GH-ISSUE #1957] Invalid composer require for psr/log #843

Closed
opened 2026-03-04 03:01:19 +03:00 by kerem · 2 comments
Owner

Originally created by @hpsam on GitHub (Mar 19, 2025).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1957

Monolog version 3 / PHP 8.3 / psr/log 2.x

In composer.json there is this require : "psr/log": "^2.0 || ^3.0".
But Monolog\Logger class (since v3.0.0) is not compatible with Psr\Log\LoggerInterface (2.x). This result in a PHP Fatal 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/ard/www/typo3conf/ext-ard/ard_composerm/vendor/monolog/monolog/src/Monolog/Logger.php on line 683

PHP Stop on first incompatible method, but all similar methods have the same problem. They declare a type on $message but interface don't do it.

Monolog\Logger class can't be more restrictive than the interface. Class could be less restrictive than interface.

2 solutions :

  • remove type Stringable|string of methods parameter to be compatible with psr/log 2 and 3
  • or remove compatibility with psr/log 2 in composer.json
Originally created by @hpsam on GitHub (Mar 19, 2025). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1957 Monolog version 3 / PHP 8.3 / psr/log 2.x In composer.json there is this require : "psr/log": "^2.0 || ^3.0". But Monolog\Logger class (since v3.0.0) is not compatible with Psr\Log\LoggerInterface (2.x). This result in a PHP Fatal 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/ard/www/typo3conf/ext-ard/ard_composerm/vendor/monolog/monolog/src/Monolog/Logger.php on line 683` PHP Stop on first incompatible method, but all similar methods have the same problem. They declare a type on $message but interface don't do it. Monolog\Logger class can't be more restrictive than the interface. Class could be less restrictive than interface. 2 solutions : - remove type **Stringable|string** of methods parameter to be compatible with psr/log 2 and 3 - or remove compatibility with psr/log 2 in composer.json
kerem 2026-03-04 03:01:19 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@Seldaek commented on GitHub (Mar 20, 2025):

I think you have psr/log 1.x there. psr/log 2.x does have the same signature as monolog (except for the void return type which was added in 3.x) https://github.com/php-fig/log/blob/2.0.0/src/LoggerInterface.php#L30

<!-- gh-comment-id:2739620367 --> @Seldaek commented on GitHub (Mar 20, 2025): I think you have [psr/log 1.x](https://github.com/php-fig/log/blob/1.1.4/Psr/Log/LoggerInterface.php) there. psr/log 2.x does have the same signature as monolog (except for the void return type which was added in 3.x) https://github.com/php-fig/log/blob/2.0.0/src/LoggerInterface.php#L30
Author
Owner

@hpsam commented on GitHub (Mar 21, 2025):

You are right, an other dependency downgrade psr/log in our project from 1.x to 2.x and I have not seen it.
Thanks

<!-- gh-comment-id:2742881003 --> @hpsam commented on GitHub (Mar 21, 2025): You are right, an other dependency downgrade psr/log in our project from 1.x to 2.x and I have not seen it. Thanks
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#843
No description provided.