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

jsonSerialize missing return type messages in PHP 8.1 #429

Open
aetikon opened this issue Mar 24, 2022 · 3 comments
Open

jsonSerialize missing return type messages in PHP 8.1 #429

aetikon opened this issue Mar 24, 2022 · 3 comments

Comments

@aetikon
Copy link

aetikon commented Mar 24, 2022

PHP 8.1 outputs several deprecation messages because the jsonSerialize() methods implemented by this package do not specify the mixed return type nor use the #[\ReturnTypeWillChange] attribute.

The message doesn't appear in PHP 8.0.

Sample message:

PHP Deprecated: Return type of net\authorize\api\contract\v1\MerchantAuthenticationType::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/vagrant/selfcare/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/MerchantAuthenticationType.php on line 261

Affected files:

lib/net/authorize/api/contract/v1/*.php

Suggested fix:

Suppress the notice by adding the #[\ReturnTypeWillChange] attribute above the method's implementation since the mixed return type is only available as of PHP 8.0.

#[\ReturnTypeWillChange]
public function jsonSerialize() { ... }
@LordPachelbel
Copy link

These deprecation notices were annoying enough that I forked and patched the code on our servers with the #[\ReturnTypeWillChange] attribute, but it should be fixed for everyone.

I can't submit a pull request for this, apparently, as per the project guidelines:

Part of the SDK is auto-generated based on the XML schema. Due to this auto-generation, we cannot merge contributions for request or response classes. You are welcome to open an issue to report problems or suggest improvements. Auto-generated classes include all files inside contract/v1 and controller folders, except controller/base.

Temporary fixes:

  • There are 175 jsonSerialize() method signatures, so if you want to patch your own fork, here's a regex to fix them all quickly:

    • Find: \n(\s+)(.+)function jsonSerialize
    • Replace: \n$1#[\\ReturnTypeWillChange]\n$1$2function jsonSerialize
  • Or you can use our fork by updating composer.json:

    "require": {
      ...
      "authorizenet/authorizenet": "dev-php8_1-jsonSerialize-deprecation-fix#b53902ebcd7d095cf5271da69db02d823ddc23d3",
      ...
    },
    ...
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/BrownBoots/authorizenet-sdk-php.git"
      }
    ]
    

@Zelfapp
Copy link

Zelfapp commented Jul 30, 2022

@LordPachelbel thank you for fork. PR's seem to be stuck for PHP 8.1 issues. Anet team, please get these PHP 8.1 updates pulled in.

@LordPachelbel
Copy link

@Zelfapp To be clear, my fork only suppresses the messages. The AuthorizeNet team might want to instead change the return type to mixed for all of the functions. It depends on how they're going to handle compatibility — that return type didn't exist before PHP 8.0 — i.e. whether they're going to maintain a separate PHP branch, or if they're going to continue with one release branch for all PHP versions.

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

No branches or pull requests

3 participants