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

Fixed PHP 8.2 deprecated dynamic property creation warning #604

Closed

Conversation

danielmorell
Copy link
Collaborator

This PR fixes the PHP 8.2 deprecated dynamic property creation warning issue #590.

Description of the change

This adds a new class ExceptionWrapper to the SDK. It is used by the ExceptionHandler::handle() and Rollbar::logUncaught() methods. Both functions need to inform the RollbarLogger::report() method that the Exception instance we are passing it is on that was caught by the Rollbar SDK. To do that we had been setting the isUncaught property on the Exception instance. However, the Exception class does not have an isUncaught property. This means we were dynamically creating the property; something PHP allows. However, in PHP 8.2 dynamic property creation has been deprecated.

ExceptionWrapper let's us wrap the exception so that it can be passed to the RollbarLogger::log() method and include an isUncaught property while keeping the log() method compliant with the PSR logging interface.

For test review purposes I pushed the test to the branch first. You can see the failed test in our CI (while the test logs are retained). Also, note, that in the latest commit to this branch the test passes.

This also fixes all the dynamic properties I could find in the test suite.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

@danielmorell danielmorell added the Type: Maintenance General up-keep, or changes that tidy an existing component or process. label Feb 20, 2023
@danielmorell danielmorell added this to the v4.0.0 milestone Feb 20, 2023
}
return $result;
$wrapper = new ExceptionWrapper($toLog, isUncaught: true);
return self::$logger->report($level, $wrapper, $context);
Copy link

@anler anler Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

Why not add another optional parameter to report that is bool $uncaught = false? I find it better because is only that method the one needing that type of information, besides I find it confusing that we pass a string | Stringeable type to report but it internally coerces it into mixed when passing it to isUncaughtLogData.

If we do this then wrapper types for the exceptions and isUncaughtLogData would no longer be needed. The problem is isUncaughtLogData is public 😅 but I'm failing to see why is it useful hence my desire to remove it altogether.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a really good question.

I was trying to keep report() as close to log() as possible. I had not considered adding an optional argument, but that would definitely work.

ExceptionHandler currently calls the RollbarLogger::log() method, but that could be updated to use report(), if we went with the optional argument.

Overall, I think that using the optional argument solution would probably reduce complexity. I like it! I'll work on that.

@danielmorell danielmorell deleted the fixed/php-8.2-deprecated-dynamic-property branch February 23, 2023 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Maintenance General up-keep, or changes that tidy an existing component or process.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP 8.2 Compatibility
2 participants