sdk-php icon indicating copy to clipboard operation
sdk-php copied to clipboard

PHP 7.4 support

Open SteveDesmond-ca opened this issue 5 years ago â€ĸ 7 comments

As of right now, ANet's PHP SDK cannot run on PHP 7.4, as it throws errors about invalid code in the various model types, e.g.

    <h4>A PHP Error was encountered</h4>

    <p>Severity: 8192</p>
    <p>Message: Cannot use "parent" when current class scope has no parent</p>
    <p>Filename: v1/MessagesType.php</p>
    <p>Line Number: 134</p>

I believe this is due to the new JIT compiler seeing things like

    return array_merge(parent::jsonSerialize(), $values);

on classes that don't actually have parents.

PR #382 already exists and appears to fix this, but even just some news that an in-house solution is in the works would be helpful.

SteveDesmond-ca avatar Jan 01 '20 16:01 SteveDesmond-ca

I also have same problem.

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/OrderType.php on line 532

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/NameAndAddressType.php on line 262

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/CustomerDataType.php on line 181

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/TransactionRequestType.php on line 1122

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/ANetApiRequestType.php on line 129

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/ANetApiResponseType.php on line 127

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/TransactionResponseType.php on line 889

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/MessagesType.php on line 134

Deprecated: Cannot use "parent" when current class scope has no parent in /var/www/html/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/MessagesType/MessageAType.php on line 97

Nix-id avatar Jul 15 '20 06:07 Nix-id

Also having the same issue with 7.4 and Deprecated: Cannot use "parent" when current class scope has no parent

witchblade32 avatar Sep 08 '20 14:09 witchblade32

Same issue on PHP 7.4.10 Cannot use "parent" when current class scope has no parent

mihaijoldis avatar Sep 18 '20 17:09 mihaijoldis

Also having this exact same issue on PHP 7.4.

aetikon avatar Sep 24 '20 19:09 aetikon

Same thing here.

JeffUssing avatar Sep 30 '20 21:09 JeffUssing

✅ I've been able to modify my clone of the codebase to work with PHP ^7.4 . It has been working well.

It's the same thing this guy did 👉 Forked Repo working with PHP ^7.4 resulting in this PR mentioned in the first comment of this issue.

I know it's ultimately Authorize.net's responsibility to fix this but it's been đŸĻ—đŸ’¤ from them and I've been reaching out for a long time. I don't know when they're going to accept accountability for this, step up to the plate, and fix it.

⚠ī¸ The issue is that all files in the lib/net/authorize/api/contract/v1 directory are autogenerated by their cross-platform compiler "based on the XML schema" of Authorize.net's API. This means a human didn't actually spend time making sure the bugged classes made logical sense in the PHP language.

🙇 Unfortunately, without possibly getting sued, I'm not allowed to distribute the fixed code to all of you due to the license agreement of their codebase unless Authorize.net gives me permission to do so, which they have not yet. But you can use the repo I mentioned above 👆. But hopefully this feedback will give you all 'some' control of your own success if Authorize.net isn't able to reconsider the decision to rely on a cross-platform compiler before PHP 7.3 reaches end of support on 6 Dec 2021.

📖 This explains the manual effort to fix all files in the lib/net/authorize/api/contract/v1 directory to work with PHP ^7.4:

  • Any class that extends another class and does not define its own method jsonSerialize(), I added that method with the same content as its parent. (Because it definitely has a parent. However, copy the method from the parent right now because we're about to change the parent's method definition in the next step)
  • Any class that does not extend another class can never have a parent. So I removed the last if(){} block in jsonSerialize() that checks for a parent class and simply return $values; always.

FYI (no changes to):

  • Any class that extends another class and also defines its own method jsonSerialize(), I left as is; no changes. (Because it definitely has a parent).

ℹī¸ I experimented with doing this an 'easier' way that involves less manual file editing and instead inheritance of a wiser jsonSerialize() method in the base classes. Ultimately things didn't behave properly in my experiment and I went down a rabbit's-hole that ultimately didn't pan-out. So I bit the bullet and just stuck to the original plan of updating all the files.

FactoryAidan avatar Oct 09 '20 06:10 FactoryAidan

Just want to link to issue 397 from here since it is discussing the same problem and suggests the dev branch "dev-master#ef297d3e2d7c1092ddabd2c376eb485aac1aa66c" as an alternative to user repos. Nobody from authorize.net is coming to the rescue. This repo appears abandoned.

rekliner avatar Jan 14 '21 17:01 rekliner

Per #407, v2.0.2 supports PHP 7.4+

SteveDesmond-ca avatar Jul 11 '23 13:07 SteveDesmond-ca