-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
Laravel Version
12.38.1
PHP Version
8.3.27
Database Driver & Version
N/A
Description
This was previously reported in #57295 (converted to discussion #57299), but it couldn't be reproduced at the time.
After digging into it, I found it happens when anything tries to access the log driver or indirectly loads Psr\Log\AbstractLogger - e.g. in a service provider's boot() method. As noted in that discussion, it happens because Composer includes an older version of psr/log which is loaded first.
In my particular case, there were several things doing that:
- LdapRecord-Laravel indirectly calls
Log::channel()from theboot()method. - My own service provider calls
Mail::alwaysTo($email);in development, which indirectly loadsAbstractLogger. - My own service provider calls
Debugbar::enable();in development, which does the same thing.
Since Composer isn't likely to upgrade psr/log any time soon, Laravel can't downgrade it, and it seems unreasonable to expect that no package ever calls those methods in boot(), I would suggest doing the event dispatch in a subprocess rather than bootstrapping Laravel inside the Composer process.
Steps To Reproduce
composer create-project --prefer-dist laravel/laravel laravel-test
cd laravel-testEdit app/Providers/AppServiceProvider.php - add any one of these lines to the boot() method:
\Log::debug('test');
\Log::driver();
\Mail::alwaysTo('example@example.com');
class_exists(\Psr\Log\AbstractLogger::class);Then run:
composer require laravel/helpers
composer remove laravel/helpersThe output includes:
Package operations: 0 installs, 0 updates, 1 removal
> Illuminate\Foundation\ComposerScripts::prePackageUninstall
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 /local/temp/laravel-test/vendor/monolog/monolog/src/Monolog/Logger.php on line 683
PHP Fatal error: Uncaught Error: Class "Monolog\Logger" not found in /local/temp/laravel-test/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php:60
Or:
Package operations: 0 installs, 0 updates, 1 removal
> Illuminate\Foundation\ComposerScripts::prePackageUninstall
PHP Fatal error: Declaration of Psr\Log\AbstractLogger::emergency(Stringable|string $message, array $context = []): void must be compatible with Psr\Log\LoggerInterface::emergency($message, array $context = []) in /local/temp/laravel-test/vendor/psr/log/src/LoggerTrait.php on line 18
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 /local/temp/laravel-test/vendor/monolog/monolog/src/Monolog/Logger.php on line 683