Skip to content

Conversation

michalkleiner
Copy link
Contributor

@michalkleiner michalkleiner commented Apr 24, 2023

Description:

Add return type mixed to satisfy the interface the class is implementing.

fixes #20627

Review

@@ -101,7 +101,7 @@ public function __toString()
return $this->setting . ' ' . implode(' OR ', $checks);
}

public function jsonSerialize()
public function jsonSerialize(): mixed
Copy link
Member

Choose a reason for hiding this comment

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

@michalkleiner The typehint mixed was introduced with PHP 8.0. See https://www.php.net/manual/en/language.types.declarations.php
So we can't use it as our code needs to be compatible with PHP 7.2+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case we can't be implementing \JsonSerializable since that's the cause of the warning.

Copy link
Member

Choose a reason for hiding this comment

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

It can be suppressed using the #[\ReturnTypeWillChange] comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that was the alternative solution. Will update the PR to add that instead of the return type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR updated

Copy link
Member

Choose a reason for hiding this comment

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

@michalkleiner I just had another thought on that. Actually we could also simply set string as return type hint.
As this is more specific as mixed, it should be compatible with that definition, but should be a lot better than the ReturnTypeWillChange workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that works for me. Updated the PR to that effect. Do we want to add it to the __toString method as well since that's the direct source of the output for the method in question?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. why not.
Imho we should try to add return types where ever it is safely possible.

@michalkleiner michalkleiner requested a review from sgiehl May 2, 2023 01:51
@michalkleiner michalkleiner added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label May 2, 2023
@sgiehl sgiehl merged commit 3823768 into 5.x-dev May 3, 2023
@sgiehl sgiehl deleted the bugfix/20627 branch May 3, 2023 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Development

Successfully merging this pull request may close these issues.

[PHP 8.1 compatibility] deprecation warning — Return type of RequiredPhpSetting::jsonSerialize
2 participants