-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Laravel 10.x / PHP 8.2.x / PHP Fatal error: Declaration of Monolog ? #46165
Comments
I'm having this bug also PHP: 8.1.15
`
` Only Occurs in Laravel 10 |
Can't use the Logger and it breaks capturing Exceptions, displays a 500 error This occurs when an exception is thrown. Because it throws a 500 and not the lovely laravel debugger screen, I only was able to catch this in sentry. It's been happening when any error is thrown. https://packagist.org/packages/monolog/monolog Seems the issue is in psr/log. Tested with APP_DEBUG=false and no maintenance page is displayed just the 500 error. So can't use the framework in production on a live system |
Composer version? |
Composer version 2.5.2 2023-02-04 14:33:22 |
Do you have the PSR extension (https://github.com/jbboehr/php-psr) installed? Uninstall it and try again. |
Removed the psr extension. removed vendor and reinstalled composer. Same issue |
Yeah think that's fixed it. |
Yeah it's logging to laravel.log now. think you need to let people know to disable the psr.so extension |
@eamon-straughn, @AegirLeet AegirLeet Hi, tested did recompile my, laradock without extension and did fresh install from composer seems it is the cause. |
Okay, removing the PSR extension did the trick for me too. |
nice to see you got it working, yeah removing the extension does work |
Hey @driesvints, The unofficial PSR extension available in PECL ships old PSR versions, and thus conflicts with many libraries. One option is to add a Much like what Laminas has already done: I would send a PR, but I am not sure which (if not all), For reference, here are some related issues:
|
Oh boy, I wish I could see this before losing 1 hour of debugging it on the weekend. I was looking at the interface and the class matched, I removed the vendor folder and tried everything. Then I noticed |
@rodrigopedra are you sure we can just add |
@driesvints no, I am not sure. I don't think extensions can be targeted by version, as regular packages are checked against their version and metadata on packagist, or on some other repository, whereas extensions are checked on the machine level. But I am not sure. On the other hand, with this extension installed, Laravel 10 just can't run, as you can see from the reports above. So I think adding it wouldn't make any harm. At least, users would have a saner error message to debug their installation problems. |
Hi all. It seems there really isn't anything we can do here. Laravel v10 is already released so if we'd add |
I had this issue with fresh laravel 10, php8.1 and composer 2.5. I fixed it by commenting out the ;extension=psr.so in my php config. I don't think this is a good solution but I'm not sure how to solve this. |
This fixed it for me. |
Does that mean there will be a fix in later versions -- Laravel 10.x? |
I noticed in my logs that I was seeing a lot of inheritance errors from the |
I had a same issue on dump-autoload PHP Fatal error: Declaration of Monolog\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with PsrExt\Log\LoggerInterface::emergency($message, array $context = []) PHP: 8.2.0 |
this solve my Issue, I removed php8.1-psr and things are working fine now |
Thanks. |
It seems the problem arises from the php-psr extension installed on the system, To see if you have the extension installed, run this command. sudo dpkg --get-selections | grep php search something like
Depending on the version of PHP that you have installed on your system, proceed to remove the package.
that should solve the problem |
In case the future me needs help on this and github actions you can disable extension with - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
tools: phpmd
extensions: mbstring, dom, fileinfo, mysql, grpc, :psr
coverage: xdebug #optional |
Description:
PHP Fatal error: Declaration of Monolog\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with PsrExt\Log\LoggerInterface::emergency($message, array $context = []) in /var/www/dev/corvid.dev/vendor/monolog/monolog/src/Monolog/Logger.php on line 669
PHP Fatal error: Uncaught Error: Class "Monolog\Logger" not found in /var/www/dev/corvid.dev/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php:59
Stack trace:
#0 /var/www/dev/corvid.dev/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php(38): Monolog\Handler\AbstractHandler->setLevel()
#1 /var/www/dev/corvid.dev/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php(49): Monolog\Handler\AbstractHandler->__construct()
#2 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(185): Monolog\Handler\StreamHandler->__construct()
#3 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(139): Illuminate\Log\LogManager->createEmergencyLogger()
#4 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(122): Illuminate\Log\LogManager->get()
#5 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(645): Illuminate\Log\LogManager->driver()
#6 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(274): Illuminate\Log\LogManager->error()
#7 /var/www/dev/corvid.dev/vendor/nunomaduro/collision/src/Adapters/Laravel/ExceptionHandler.php(46): Illuminate\Foundation\Exceptions\Handler->report()
#8 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(182): NunoMaduro\Collision\Adapters\Laravel\ExceptionHandler->report()
#9 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(226): Illuminate\Foundation\Bootstrap\HandleExceptions->handleException()
#10 /var/www/dev/corvid.dev/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(250): Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
#11 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap{closure}()
#12 {main}
thrown in /var/www/dev/corvid.dev/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php on line 59
Steps To Reproduce:
easy to get this bug run in cli: php artisan asdas
composer.json
The text was updated successfully, but these errors were encountered: