-
Notifications
You must be signed in to change notification settings - Fork 43
Fix PHP 8.2 deprecation warnings caused by dynamic properties on the $order object #786
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
Fix PHP 8.2 deprecation warnings caused by dynamic properties on the $order object #786
Conversation
|
Hey sorry I haven't had a chance to get to this yet. Just noting that I did start testing it with Authorize.net, but unfortunately that particular code base is riddled with bits that require migrating to the new Just noting that due to what I was seeing, we will have to put this change in a major framework release, which is fine, but just making a note of it. Because we stop setting the props dynamically completely it breaks any integration that hasn't gone through all the updates. Some minor feedback as I glance through what updates would be required: it would be nice to add a new helper method to the framework specifically to get the order payment. As in: some kind of But it would save some repetition and abstract things out a bit nicely for gateways. |
|
Having a list of properties that gateways need to update will be helpful for the upgrade guide: On order object:
|
|
Just thinking about this some more... I wonder if it's possible to make the new behaviour opt-in (for a while) in order to maintain backwards compatibility and remove the need to put this into a major release. I'm thinking:
|
|
Hi @agibson-godaddy, Thanks for checking on this and sharing thoughts here.
Yes, we can do this. In
Yes, need to update the codebase to test this. I did updated the braintree codebase to test and validate this. However, once we make this opt-in based you will be able to test it directly.
👍 I'm out next week, but I’ll try to make these changes once I get some time to work on them. Thanks! |
|
Thanks @iamdharmesh !
Just an update that I did finally get it updated enough to do some very light testing (regular transaction only) and it worked! |
…n-framework into fix/781
… use of Dynamic_Props class opt-in only.
|
Hi @agibson-godaddy 👋, I’ve made this opt-in only, and developers now need to use a filter to opt in. I also added an OrderHelper class to simplify getting/setting common props and included an upgrade guide in the PR description. Could you please review this once? Thanks! |
|
@agibson-godaddy following up here to see if you can help review the above. Thanks! |
|
Sorry folks -- I'll get to it as soon as I can! Will try to take a look this week. |
QA
|
|
I think this is all working nicely for me. Have you folks also tested this in your own integration(s)? |
|
Thanks @agibson-godaddy
Yes, I have tested this with Braintree extension (with and without opt-in) and it's working fine. |
agibson-godaddy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to merge this into the release branch, but we'll need to work on an upgrade guide before we can make the release official.
Thanks so much for your work on this @iamdharmesh ! It's hugely appreciated.
531f046
into
godaddy-wordpress:release/6.0.0
|
Thanks for merging this @agibson-godaddy.
I’ve added a short version of the Upgrade Guide in PR description, but I’m happy to include more details, add any specific points you’d like, or update anything as needed. |
|
Hi @agibson-godaddy any ETA on when this will get released? |
Summary
This PR fixes deprecation warnings in PHP 8.2 caused by dynamic properties set on the
WC_Orderobject. It introduces aDynamic_Propsclass to handle dynamic properties usingWeakMapfor PHP 8.0 and above, while continuing to set dynamic properties directly on the$orderobject for PHP versions below 8.0.Closes #781
Details
This PR introduces a new
Dynamic_Propsclass to manage dynamic property storage for WooCommerce order objects. The changes ensure compatibility with PHP 8.2+, where dynamic properties are deprecated, while maintaining backwards compatibility with PHP 7.4+. The updates replace direct property access with theDynamic_Propsclass in various payment gateway handlers and classes.Key Changes
Introduction of the
Dynamic_PropsClassDynamic_Propsclass inwoocommerce/payment-gateway/Dynamic_Props.phpto handle dynamic property storage usingWeakMapfor PHP 8.0+ and fallback mechanisms for PHP 7.4+. This includes methods for setting, getting, and unsetting dynamic properties on order objects.Updates to Various Classes
Dynamic_Propsfor handling payment-related properties, replacing direct object property access (e.g.,payment->token,payment->account_number) withDynamic_Props::get()andDynamic_Props::set().Note
I have evaluated different approaches from "Approach 4", keeping in mind that plugins using this framework should require minimal changes when upgrading to the new version. Based on that, I have proceeded with this approach. However, I’m open to discussing and implementing other approaches if you believe they offer advantages over this one.
Upgrade Guide
Upgrading to v6.0.0
This guide helps you upgrade your payment gateway plugin from v5.x.x to v6.0.0.
Dynamic Properties Management
Starting with v6.0.0, we've introduced a new way to handle dynamic properties on WooCommerce order objects to address PHP 8.2 deprecation warnings. This change is opt-in, meaning you can choose when to adopt the new approach.
Background
In PHP 8.2, setting dynamic properties on objects is deprecated. This affects how we store custom data on WooCommerce order objects. To future-proof our codebase, we've introduced a new
Dynamic_Propsclass that provides a standardized way to handle these properties.Opting In
By default, the framework continues to use the legacy approach (directly setting properties on order objects). To opt into the new approach:
Required Changes
Once opted in, you'll need to update how you get and set dynamic properties on order objects. Here are the common properties that need updating:
Common Dynamic Properties
customer_idpaymentpayment_totaldescriptioncapturerefundunique_transaction_refBefore (Legacy Approach)
After (New Approach)
Example
Here's a complete example of migrating a payment processing method:
Compatibility Notes
Additional Resources
UI Changes
N/A
QA
Setup
Steps
Run Following tests with PHP 8.2+ and PHP 7.4:
Before merge