framework: Laravel 10.x / PHP 8.2.x / PHP Fatal error: Declaration of Monolog ?

  • Laravel Version: 10.0.3
  • PHP Version: 8.2.3
  • Database Driver MySQL & Version: 8.0.32

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

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^8.2",
        "guzzlehttp/guzzle": "^7.5",
        "laravel/framework": "^10.0.3",
        "laravel/sanctum": "^3.2.1",
        "laravel/telescope": "^4.13.2",
        "laravel/tinker": "^2.8"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "^3.8",
        "barryvdh/laravel-ide-helper": "^2.13",
        "fakerphp/faker": "^1.21.0",
        "laravel/pint": "^1.5",
        "mockery/mockery": "^1.5.1",
        "nunomaduro/collision": "^7.0.4",
        "nunomaduro/larastan": "^2.4.1",
        "phpunit/phpunit": "^10.0.7",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 25 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Do you have the PSR extension (https://github.com/jbboehr/php-psr) installed? Uninstall it and try again.

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

php8.2-psr
php7.4-psr

Depending on the version of PHP that you have installed on your system, proceed to remove the package.

sudo apt remove php8.2-psr

that should solve the problem

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 conflict entry to composer.json so developers are aware they shouldn’t be using this extension with a newer Laravel version.

Much like what Laminas has already done:

https://github.com/laminas/laminas-servicemanager/blob/f32cdaea6dcba17b5701e46455a80ce4006970cb/composer.json#L55-L56

I would send a PR, but I am not sure which (if not all), composer.json files should be updated.

For reference, here are some related issues:

I noticed in my logs that I was seeing a lot of inheritance errors from the PsrExt namespace, and realised that I’d inadvertently installed the php-psr package via my OS’s package manager. In my case apt remove php8.1-psr resolved my issue.

In case the future me needs help on this and github actions you can disable extension with : so the :psr did it

      - 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

I noticed in my logs that I was seeing a lot of inheritance errors from the PsrExt namespace, and realised that I’d inadvertently installed the php-psr package via my OS’s package manager. In my case apt remove php8.1-psr resolved my issue.

this solve my Issue, I removed php8.1-psr and things are working fine now

Does that mean there will be a fix in later versions – Laravel 10.x?

Yeah it’s logging to laravel.log now. think you need to let people know to disable the psr.so extension

Okay, removing the PSR extension did the trick for me too.

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

This fixed it for me.

Hi all. It seems there really isn’t anything we can do here. Laravel v10 is already released so if we’d add ext-psr to the conflicts now it wouldn’t prevent people from installing Laravel with the v10.0.0 tag. So that’s not really a solution anymore. We’re just going to have to ask you to uninstall that extension if you want to use Laravel v10.