bugsnag / bugsnag-laravel

BugSnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
https://docs.bugsnag.com/platforms/php/laravel/
MIT License
876 stars 129 forks source link

PHP 8.1 Deprecated messages #466

Open aglipanci opened 2 years ago

aglipanci commented 2 years ago

PHP 8.1 Deprecated messages

PHP Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /var/www/html/vendor/bugsnag/bugsnag/src/Configuration.php on line 362

Steps to reproduce

  1. Install latest version of Laravel using PHP 8.1
  2. Install the latest version of Bugsnag for Laravel
  3. Enable error logs

Environment

mattdyoung commented 2 years ago

Thanks! We'll take a look.

niladam commented 2 years ago

I did some investigations and it appears the issue appears on line #362 (where @aglipanci also said) but after fixing that, it appears again on line #320.

So the issue appears to be something that's PHP 8.1 related as the $subject no longer accepts null as a parameter.

So the quickfix would be to just replace null with '' or "" (empty string); This should work on PHP < 8.1 as well :)

So basically just replace (line 362):

if ($stripPathRegex && @preg_match($stripPathRegex, null) === false) {

with

if ($stripPathRegex && @preg_match($stripPathRegex, '') === false) {

AND (line 320)

if ($projectRootRegex && @preg_match($projectRootRegex, null) === false) {

with

if ($projectRootRegex && @preg_match($projectRootRegex, '') === false) {
indigoram89 commented 2 years ago

Any ideas??

indigoram89 commented 2 years ago

Thanks! We'll take a look.

Can you fix it at last?

GrahamCampbell commented 2 years ago

I'll take a look. I think this should be an easy fix.

imjoehaines commented 2 years ago

I haven't been able to reproduce this in a new Laravel project, other than in the artisan tinker REPL. This is caused by PsySH (the library used to provide the REPL) not respecting the error suppression operator, which is used in both lines highlighted in this issue. I've opened an issue there to track this, but it's a tricky problem to solve: https://github.com/bobthecow/psysh/issues/702

We will fix this specific deprecation, but that doesn't solve the whole issue. The reason we're using the error suppression operator is to suppress warnings that may be raised when passing an invalid regex to preg_match: https://3v4l.org/ZGeLF. Therefore even after the deprecation is fixed, you could still see warnings coming from that line, but they should never be visible because of the @ operator

Can you confirm if the Tinker REPL where you're seeing these deprecations? If not, it'd be useful to know what is logging them because it will be caused by a bug in an error handler. Laravel's error handler does handle this correctly, so it's likely to be a third party package rather than Laravel directly

GrahamCampbell commented 2 years ago

It depends on your default error level. In any case, we should not calling code in a deprecated way.