PHP Fatal Error Monolog/PSR Version Incompatibility
Description
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 /Users/len/Sites/dev.bookdiscovery.mamp/wp-content/composer/vendor/monolog/monolog/src/Monolog/Logger.php on line 681
Steps to reproduce
Install typesense-php with composer use Typesense/Client $client = new Client()
Expected Behavior
No errors
Actual Behavior
Fatal error
Metadata
**PHP Version: 8.1
Typesense Version: 26
OS: Ubuntu 24.01
The problem turned out to be related to the versions of monolog and psr installed by composer. Apparently there is an issue with monolog 3+. These threads were helpful in diagnosing:
https://github.com/composer/composer/issues/11246 https://stackoverflow.com/questions/75696889/fatal-error-declaration-of-monolog-loggeremergencystringablestring-message
The solution was to downgrade monolog and psr. I accomplished this by adding the following lines to the composer.json file in the project root:
"monolog/monolog": "^2.5",
"psr/log": "^2.0"
I then updated monolog and psr with the following composer command (composer required simultaneous update of monolog and psr for this operation):
composer update monolog/monolog psr/log
This operation successfully downgraded monolog from version 3.6.0 to version 2.9.3 and psr from version 3.0.0 to version 2.0.0. The TypeSense PHP client is now working.