AuthorizeNet / sample-code-php

This repository contains working code samples which demonstrate php integration with the Authorize.Net API
MIT License
175 stars 197 forks source link

JsonSerializable throws warnings in newer PHP #180

Open scottw-finao opened 3 months ago

scottw-finao commented 3 months ago

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