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

JsonSerializable throws warnings in newer PHP #180

Open
scottw-finao opened this issue Mar 12, 2024 · 0 comments
Open

JsonSerializable throws warnings in newer PHP #180

scottw-finao opened this issue Mar 12, 2024 · 0 comments

Comments

@scottw-finao
Copy link

scottw-finao commented Mar 12, 2024

I'm using PHP 8.x and the lack of a return type :mixed on the various library JsonSerialize functions throws out warnings all over the place when using the lib in newer php.

There are a couple of fixes. For newer php, the preferred method is to add the :mixed return type on any definitions of JsonSerialize so they are compatible with the interface.

    // Json Serialize Code
    public function jsonSerialize(): mixed { /* code */ }

But you can also add a comment above the function that older version of php will ignore and newer ones will suppress the warning.

e.g.:

    // Json Serialize Code
    #[\ReturnTypeWillChange]
    public function jsonSerialize() { /* code */ }

See ReturnTypeWillChange

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

No branches or pull requests

1 participant