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

Support PHP 8.1 for sentry-php 2.x #1247

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function offsetExists($offset): bool
/**
* {@inheritdoc}
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a feasible change, it would break the app for everyone below PHP 8.1

Copy link
Contributor Author

@annuh annuh Oct 7, 2021

Choose a reason for hiding this comment

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

Are you sure about that?

According to the composer.json the minimal PHP version is 7.1 ("php": "^7.1",). Return type declarations are supported since PHP 7.0 and these declarations can be overridden in child classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

The mixed type was implemented in this RFC for PHP 8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's true...

The alternative is to add the #[\ReturnTypeWillChange] attribute, but that will break compatibility for < PHP 8.0. 😬

Fatal error:  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Sentry\Context\Context::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/sentry/sentry/src/Context/Context.php:152

{
return $this->data[$offset];
}
Expand Down