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

PHP 8.2 deprecation warnings #35763

Closed
2 of 5 tasks
rodrigoprimo opened this issue Nov 29, 2022 · 23 comments
Closed
2 of 5 tasks

PHP 8.2 deprecation warnings #35763

rodrigoprimo opened this issue Nov 29, 2022 · 23 comments
Labels
needs: triage feedback Issues for which we requested feedback from the author and received it. plugin: woocommerce Issues related to the WooCommerce Core plugin. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton type: bug The issue is a confirmed bug. type: technical debt This issue/PR represents/solves the technical debt of the project.

Comments

@rodrigoprimo
Copy link
Contributor

rodrigoprimo commented Nov 29, 2022

Prerequisites

  • I have carried out troubleshooting steps and I believe I have found a bug.
  • I have searched for similar bugs in both open and closed issues and cannot find a duplicate.

Describe the bug

Similar to #33808 which refers to PHP 8.1, I'm seeing a few deprecation warnings when running WooCommerce with PHP 8.2.0 RC6.

Expected behavior

WooCommerce fully compatible with PHP 8.2 without any deprecation warnings. Please note that those warnings will become fatal errors in PHP 9.0.

Actual behavior

Here is the list of deprecations warnings that I'm seeing:

PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 1705
PHP Deprecated: Creation of dynamic property WooCommerce::$api is deprecated in /wp-core/wp-content/plugins/woocommerce/includes/class-woocommerce.php on line 556
PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/src/Internal/DownloadPermissionsAdjuster.php on line 157
PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php on line 148
PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php on line 162
PHP Deprecated: Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostToOrderTableMigrator::$table_names is deprecated in /wp-core/wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderTableMigrator.php on line 25
PHP Deprecated: Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostToOrderAddressTableMigrator::$table_names is deprecated in /wp-core/wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderAddressTableMigrator.php on line 42
PHP Deprecated: Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostToOrderOpTableMigrator::$table_names is deprecated in /wp-core/wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderOpTableMigrator.php on line 26
PHP Deprecated: Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostMetaToOrderMetaMigrator::$table_names is deprecated in /wp-core/wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostMetaToOrderMetaMigrator.php on line 43
PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/src/Internal/Features/FeaturesController.php on line 398
PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/src/Admin/API/Reports/Orders/Stats/DataStore.php on line 381
PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/src/Admin/API/Reports/Orders/Stats/DataStore.php on line 700
PHP Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /wp-core/wp-content/plugins/woocommerce/src/Utilities/FeaturesUtil.php on line 62
PHP Deprecated: Creation of dynamic property WC_Countries::$countries is deprecated in /wp-core/wp-content/plugins/woocommerce/includes/class-wc-countries.php on line 51
PHP Deprecated: Creation of dynamic property WC_Cart::$coupon_discount_totals is deprecated in /wp-core/wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-cart.php on line 266
PHP Deprecated: Creation of dynamic property WC_Cart::$coupon_discount_tax_totals is deprecated in /wp-core/wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-cart.php on line 266
12x DEPRECATION: Creation of dynamic property Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableQuery::$orders is deprecated /wp-core/wp-content/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php:1009
DEPRECATION: Creation of dynamic property WC_Email_New_Order::$email_type is deprecated /wp-core/wp-content/plugins/woocommerce/includes/emails/class-wc-email.php:254
3x DEPRECATION: Creation of dynamic property WC_Order::$refunds is deprecated /wp-core/wp-content/plugins/woocommerce/includes/class-wc-order.php:1999
DEPRECATION: Creation of dynamic property WC_Gateway_Paypal::$testmode is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php:60
DEPRECATION: Creation of dynamic property WC_Gateway_Paypal::$debug is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php:61
DEPRECATION: Creation of dynamic property WC_Gateway_Paypal::$email is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php:62
DEPRECATION: Creation of dynamic property WC_Gateway_Paypal::$receiver_email is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php:63
DEPRECATION: Creation of dynamic property WC_Gateway_Paypal::$identity_token is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php:64
DEPRECATION: Creation of dynamic property WC_Gateway_BACS::$instructions is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/bacs/class-wc-gateway-bacs.php:49
DEPRECATION: Creation of dynamic property WC_Gateway_BACS::$account_details is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/bacs/class-wc-gateway-bacs.php:52
DEPRECATION: Creation of dynamic property WC_Gateway_Cheque::$instructions is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/cheque/class-wc-gateway-cheque.php:41
DEPRECATION: Creation of dynamic property WC_Gateway_COD::$instructions is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/cod/class-wc-gateway-cod.php:40
DEPRECATION: Creation of dynamic property WC_Gateway_COD::$enable_for_methods is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/cod/class-wc-gateway-cod.php:41
DEPRECATION: Creation of dynamic property WC_Gateway_COD::$enable_for_virtual is deprecated /wp-core/wp-content/plugins/woocommerce/includes/gateways/cod/class-wc-gateway-cod.php:42

Steps to reproduce

I got those warnings while running the MailPoet automated test suite with PHP 8.2 RC6 (https://app.circleci.com/pipelines/github/mailpoet/mailpoet/12388/workflows/c2b20f29-eb1b-4e3a-abc2-15306b59b720/jobs/211887). MailPoet test suite uses the latest version of WooCommerce to perform part of the tests. So unfortunately I don't have instructions on how to reproduce those warnings with just WooCommerce, but I imagine that most of them will show up by just running WooCommerce with PHP 8.2 RC6 and visiting a few pages.

WordPress Environment

Not applicable per what was mentioned above.

Isolating the problem

  • I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
  • This bug happens with a default WordPress theme active, or Storefront.
  • I can reproduce this bug consistently using the steps above.
@github-actions github-actions bot added the status: awaiting triage This is a newly created issue waiting for triage. label Nov 29, 2022
@jonathansadowski jonathansadowski added type: bug The issue is a confirmed bug. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: prioritization and removed status: awaiting triage This is a newly created issue waiting for triage. labels Nov 30, 2022
@pacmanito
Copy link

I have some more:

Deprecated: Creation of dynamic property Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema::$image_attachment_schema is deprecated in \wp-content\plugins\woocommerce\packages\woocommerce-blocks\src\StoreApi\Schemas\V1\CheckoutSchema.php on line 51
Deprecated: Creation of dynamic property Automattic\WooCommerce\Admin\API\Init::$Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators\Controller is deprecated in \wp-content\plugins\woocommerce\src\Admin\API\Init.php on line 127

@pacmanito
Copy link

Please fix code in init.php, line 127 as it produces insane amount of deprecation notices.

@DynamicArray
Copy link
Contributor

It looks like there is a fairly simple - if short-term - solution to the immediate problem of the debug log filling up with '000s of deprecated notices:

#[AllowDynamicProperties]

https://php.watch/versions/8.2/dynamic-properties-deprecated

@barryhughes
Copy link
Member

@wvega 👋🏽 ... quick check: is more work required here given the above merged PRs?

@barryhughes barryhughes added priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. and removed status: prioritization labels Jan 26, 2023
@wvega
Copy link
Contributor

wvega commented Jan 26, 2023

Hey there @barryhughes! Yes, we need small fixes in at least the following files:

	modified:   plugins/woocommerce/includes/class-wc-countries.php
	modified:   plugins/woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
	modified:   plugins/woocommerce/includes/legacy/class-wc-legacy-cart.php
	modified:   plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostMetaToOrderMetaMigrator.php
	modified:   plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderAddressTableMigrator.php
	modified:   plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderOpTableMigrator.php
	modified:   plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderTableMigrator.php
	modified:   plugins/woocommerce/src/Database/Migrations/MetaToCustomTableMigrator.php
	modified:   plugins/woocommerce/src/Database/Migrations/MetaToMetaTableMigrator.php

Those cover the deprecation warnings that I see while running tests locally, but I believe the comments in this issue include other warnings that I haven't tracked down.

Since those files touch different areas, my plan is to open a couple other PRs with subsets of those changes, but I haven't had the time to prepare those PRs and write tests where necessary.

@barryhughes
Copy link
Member

Excellent—thanks for confirming 🤝

@bbceg
Copy link

bbceg commented Feb 3, 2023

Not sure how helpful this is, but this should sort the strstr error on line 139 of includes/wc-page-functions.php (which I noticed wasn't in your list above but is mentioned in #33808 ).

if ( ( $path && strstr( $path, $customer_logout ) ) || ( $query && strstr( $query, $customer_logout ) ) ) {

Hope that does help, apologies if not!

@unfulvio-godaddy
Copy link
Contributor

Related discussion from 2021: #31316

@CreativeDive
Copy link

CreativeDive commented Mar 27, 2023

One day until the WP 6.2 release I get still these deprecated warnings with PHP 8.2:

Deprecated | Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostToOrderTableMigrator::$table_names is deprecated | 1 | +wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderTableMigrator.php:25

Deprecated | Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostToOrderAddressTableMigrator::$table_names is deprecated | 2 | +wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderAddressTableMigrator.php:42

Deprecated | Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostToOrderOpTableMigrator::$table_names is deprecated | 1 | +wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostToOrderOpTableMigrator.php:26

Deprecated | Creation of dynamic property Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostMetaToOrderMetaMigrator::$table_names is deprecated | 1 | +wp-content/plugins/woocommerce/src/Database/Migrations/CustomOrderTable/PostMetaToOrderMetaMigrator.php:43

Deprecated | Creation of dynamic property WC_Countries::$countries is deprecated | 1 | +wp-content/plugins/woocommerce/includes/class-wc-countries.php:51

Deprecated | Creation of dynamic property WC_Cart::$coupon_discount_totals is deprecated | 1 | +wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-cart.php:266

Deprecated | Creation of dynamic property WC_Cart::$coupon_discount_tax_totals is deprecated | 1 | +wp-content/plugins/woocommerce/includes/legacy/class-wc-legacy-cart.php:266

@picocodes
Copy link
Contributor

Monitoring error logs is a nightmare since this adds dozens of new lines per page load. All you have to do is add #[\AllowDynamicProperties] at the top of the affected class declarations.

@Chouby
Copy link
Contributor

Chouby commented Jun 21, 2023

I see that #33808 is closed and I've read a comment from @rrennick that deprecation warnings for PHP 8.2 are planned to be addressed in WC 7.9 currently in beta. So here are the last 4 that I can find when running our PHPUnit tests against the latest development version (some may still related to PHP 8.1):

PHP Deprecated:  round(): Passing null to parameter #1 ($num) of type int|float is deprecated in /home/travis/build/polylang/polylang-wc/tmp/woocommerce/plugins/woocommerce/src/Admin/PageController.php on line 461
PHP Deprecated:  Automatic conversion of false to array is deprecated in /home/travis/build/polylang/polylang-wc/tmp/woocommerce/plugins/woocommerce/src/Admin/DataSourcePoller.php on line 138
PHP Deprecated:  Creation of dynamic property WC_Order_Item_Product::$legacy_values is deprecated in /home/travis/build/polylang/polylang-wc/tmp/woocommerce/plugins/woocommerce/includes/class-wc-checkout.php on line 517
PHP Deprecated:  Creation of dynamic property WC_Order_Item_Product::$legacy_cart_item_key is deprecated in /home/travis/build/polylang/polylang-wc/tmp/woocommerce/plugins/woocommerce/includes/class-wc-checkout.php on line 518

Hope it helps.

@barryhughes
Copy link
Member

All you have to do is add #[\AllowDynamicProperties] at the top of the affected class declarations.

There are places where we may do this, but it's worth noting this isn't always suitable, and often will not be the best fix. Adding it everywhere would work against the reason PHP decided to deprecate dynamic property creation it in the first place.

@rrennick
Copy link
Contributor

@Chouby Thanks for reporting these. As requested in the comment you referenced, could you create new issues for warnings/errors that had not been previously reported (and addressed)? It's much easier & faster to fix these in small batches/PRs than to try to do a single PR that addresses all of them.

"The fixes for reported PHP 8.2 issues should also be addressed in WC 7.9.0. Create a new issue if we missed any or you find any new ones that haven't been reported."

@Chouby
Copy link
Contributor

Chouby commented Jun 21, 2023

As you prefer. I opened 3 new issues: #38857 (combining the last 2 notices I reported as they are very similar), #38858 and #38860.

@EjayhanFernandes
Copy link

6586109-zen

rodrigoprimo added a commit to mailpoet/mailpoet that referenced this issue Oct 17, 2023
WooCommerce core generates a few deprecated notices when running
with PHP 8.2. This was breaking our CircleCI build. This commit adds a
workaround to this problem by manually updating WooCommerce
core files. The workaround can be removed once
woocommerce/woocommerce#35763 is
addressed.

[MAILPOET-4620]
@rrennick
Copy link
Contributor

@rodrigoprimo I think we got all of these. Could you confirm?

@rrennick rrennick added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. type: technical debt This issue/PR represents/solves the technical debt of the project. team: Proton labels Nov 15, 2023
@rodrigoprimo
Copy link
Contributor Author

@rrennick, thanks for working on this. Were all the changes already released? I'm asking because the easiest way for me would be to check this against a released version of WooCommerce. If they still need to be released, can I get a nightly build somewhere?

@github-actions github-actions bot added needs: triage feedback Issues for which we requested feedback from the author and received it. and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Nov 20, 2023
@rrennick
Copy link
Contributor

@rodrigoprimo They should all be addressed in WC 8.3.

@rrennick rrennick added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. and removed needs: triage feedback Issues for which we requested feedback from the author and received it. labels Nov 20, 2023
@rodrigoprimo
Copy link
Contributor Author

rodrigoprimo commented Nov 20, 2023

@rrennick, I ran our test suite again and found three more deprecations that I believe I missed before:

Deprecated: Automatic conversion of false to array is deprecated in /var/www/html/wp-content/plugins/woocommerce/src/Admin/DataSourcePoller.php:138
Deprecated: Creation of dynamic property WC_Order_Item_Product::$legacy_values is deprecated in /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-checkout.php:517
Deprecated: Creation of dynamic property WC_Order_Item_Product::$legacy_cart_item_key is deprecated in /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-checkout.php:518

I can confirm that the deprecations that I had reported earlier were fixed. Thanks!

@github-actions github-actions bot added needs: triage feedback Issues for which we requested feedback from the author and received it. and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Nov 20, 2023
@Chouby
Copy link
Contributor

Chouby commented Nov 20, 2023

I confirm. I already reported them in #38857 and #38860.

@rrennick
Copy link
Contributor

@rodrigoprimo Thanks. Both have already been reported

I'm not able to reproduce this one running the unit tests in either 8.2 or 8.3RC5. Could you look at your tests for the code that is triggering these warnings?

@rrennick rrennick added needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. and removed needs: triage feedback Issues for which we requested feedback from the author and received it. labels Nov 21, 2023
@rodrigoprimo
Copy link
Contributor Author

Good to know that they have been reported already.

I'm not able to reproduce this one running the unit tests in either 8.2 or 8.3RC5. Could you look at your tests for the code that is triggering these warnings?
#38857

We have the full stack trace for the error: https://output.circle-artifacts.com/output/job/5540c07a-103e-410a-9409-ecaadf150b2d/artifacts/0/tests/_output/exceptions/error--2023-11-20--20-07--065edcdbe7.html

Does this help? You can see more examples in the "Artifacts" section: https://app.circleci.com/pipelines/github/mailpoet/mailpoet/16266/workflows/1d7a02d6-41a3-48b4-a657-e6e012836e16/jobs/276027/artifacts

The warnings are being triggered by a few of our acceptance tests that check for some of MailPoet's integrations with WooCommerce.

@github-actions github-actions bot added needs: triage feedback Issues for which we requested feedback from the author and received it. and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Nov 22, 2023
@rrennick
Copy link
Contributor

@rodrigoprimo Thanks for the info. I'll close this as we have the issues covered in the two linked issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: triage feedback Issues for which we requested feedback from the author and received it. plugin: woocommerce Issues related to the WooCommerce Core plugin. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton type: bug The issue is a confirmed bug. type: technical debt This issue/PR represents/solves the technical debt of the project.
Projects
None yet
Development

No branches or pull requests