sdk-php
sdk-php copied to clipboard
PHP 7.4 support
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 parent
s.
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.
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
Also having the same issue with 7.4 and Deprecated: Cannot use "parent" when current class scope has no parent
Same issue on PHP 7.4.10 Cannot use "parent" when current class scope has no parent
Also having this exact same issue on PHP 7.4.
Same thing here.
â
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 methodjsonSerialize()
, 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 lastif(){}
block injsonSerialize()
that checks for a parent class and simplyreturn $values;
always.
FYI (no changes to):
- Any class that
extends
another class and also defines its own methodjsonSerialize()
, 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.
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.
Per #407, v2.0.2 supports PHP 7.4+