Skip to content
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

[8.x] Logs deprecations instead of treating them as exceptions #39219

Merged
merged 4 commits into from
Oct 18, 2021

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented Oct 15, 2021

This pull request changes the way Laravel's exception handler treats PHP deprecations.

Until today, Laravel always turn E_DEPRECATION or E_USER_DEPRECATION level errors into exceptions. In other words, if we were to use str_contains('', null) in PHP 8.1, Laravel would convert that deprecation into an Error Exception that gets reported on the Exception Handler, and rendered on the browser.

This pull request - just like Symfony - proposes that we start to ignore PHP deprecations and userland deprecations. Meaning that deprecations like str_contains('', null) in PHP 8.1 would not cause the program to stop. So, by default, if this pull request gets merged, no error exceptions appear on the browser or on the logger.

This pull request also introduces a new deprecations log channel that can be configured by the user. This channel, uses the null driver by default, yet the user can configure a real driver like so:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    /*
    |--------------------------------------------------------------------------
    | Deprecations Log Channel
    |--------------------------------------------------------------------------
    |
    | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Eiuro,
    | adridens, iniquum, hac quidem de re; Nihil enim hoc differt.
    | Quodsi ipsam honestatem undique pertectam atque absolutam.
    |
    */

    'deprecations' => env('LOG_DEPRECATIONS_CHANNEL', 'stack'),

    // ..
]

Of course, this pull request also configures PHPUnit differently, using the convertDeprecationsToExceptions flag so deprecations don't get treated as exceptions on tests.

If this pull request gets merged, changes will be necessary on:

  • Laravel Skeleton: config/logging.php, bump framework version, and phpunit version.
  • Lumen Framework: Copy/Past the code of this pull request
  • Lumen Skeleton: config/logging.php, bump framework version, and phpunit version.

@ankurk91
Copy link
Contributor

How services like bugsnag/sentry would behave after this change?
Specially on php 8.1.

@GrahamCampbell
Copy link
Member

No changes required. Deprecations shouldn't be sent to those tools. They are error monitoring, not logging.

@sergiy-petrov
Copy link

@nunomaduro isn't this a BC break? For example, some users asserting in their test cases that deprecation warning is thrown, but after upgrading framework their tests will fail

@sergiy-petrov
Copy link

@nunomaduro

Example:

I found test case in one open-source project that is failing now due to this change, find the link below

https://github.com/sergiy-petrov/laravel-firebase/runs/3967313296?check_suite_focus=true

@nunomaduro
Copy link
Member Author

@sergiy-petrov We should see this as a bug fix, to be honest. Laravel should not throw exceptions on deprecations to begin with.

@sergiy-petrov
Copy link

@nunomaduro so if this is a bug fix, is this gonna be merged into 6.x?

@driesvints
Copy link
Member

@sergiy-petrov no this was for php 8.1 specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants