Prerequisites
Describe the bug
WooCommerce uses some obsolete code for PHP 8.1
Upon visitting any backoffice page, we can see the errors with the help of Query Monitor plugin.
These are only warnings, however some refactor appears to be required in order to ensure proper PHP 8.1 compatibility and especially to prepare for PHP 8.2 which would probably transform these warnings into errors.
Expected behavior
Running "Query Monitor" extension and, we shouldn't see deprecated functions when using PHP 8.1.
Actual behavior
Many deprecated functions/classes and so on are present.
It is best for a dev to check it directly with Query Monitor, but here are some examples:
Visitting shop's homepage we can see the followings:
class_exists(): Passing null to parameter #1 ($class) of type string is deprecated | wp-content/plugins/woocommerce/includes/wc-core-functions.php:2050
explode(): Passing null to parameter #2 ($string) of type string is deprecated | wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php:371
Visitting /wp-admin/ shows:
class_exists(): Passing null to parameter #1 ($class) of type string is deprecated | wp-content/plugins/woocommerce/includes/wc-core-functions.php:2050
Return type of ActionScheduler_DateTime::setTimezone($timezone) should either be compatible with DateTime::setTimezone(DateTimeZone $timezone): DateTime, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice | wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_DateTime.php:60
Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice | wp-includes/Requests/Utility/CaseInsensitiveDictionary.php:40
Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice | wp-includes/Requests/Cookie/Jar.php:63
explode(): Passing null to parameter #2 ($string) of type string is deprecated | wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php:371
parse_str(): Passing null to parameter #1 ($string) of type string is deprecated | wp-content/plugins/woocommerce/src/Admin/PageController.php:128
Steps to reproduce
Setup a WordPress with WooCommerce extension, powered by PHP 8.1 on the server.
Install Query Monitor extension.
Check PHP errors and warnings, and see loads of them.
WordPress Environment
PHP 8.1.7
WP 6.0
WooCommerce 6.6.1
`
WordPress Environment
WordPress address (URL): https://woocommercetest.terageek.org
Site address (URL): https://woocommercetest.terageek.org
WC Version: 6.6.1
REST API Version: ✔ 6.6.1
WC Blocks Version: ✔ 7.6.2
Action Scheduler Version: ✔ 3.4.0
Log Directory Writable: ✔
WP Version: 6.0
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: ✔
Language: en_US
External object cache: –
Server Environment
Server Info: Apache
PHP Version: 8.1.7
PHP Post Max Size: 16 MB
PHP Time Limit: 120
PHP Max Input Vars: 1000
cURL Version: 7.74.0
OpenSSL/1.1.1n
SUHOSIN Installed: –
MySQL Version: 10.6.8-MariaDB-1:10.6.8+maria~bullseye
Max Upload Size: 16 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔
Database
WC Database Version: 6.6.1
WC Database Prefix: hJr0qh9_
Total Database Size: 3.81MB
Database Data Size: 2.37MB
Database Index Size: 1.44MB
hJr0qh9_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
hJr0qh9_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
hJr0qh9_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_options: Data: 1.44MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_postmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_posts: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
hJr0qh9_wc_admin_notes: Data: 0.05MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
hJr0qh9_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
hJr0qh9_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
Post Type Counts
attachment: 1
page: 7
post: 2
Security
Secure connection (HTTPS): ✔
Hide errors from visitors: ✔
Active Plugins (2)
Query Monitor: by John Blackbourn – 3.9.0
WooCommerce: by Automattic – 6.6.1
Inactive Plugins (0)
Dropin Plugins (1)
db.php: Query Monitor Database Class (Drop-in)
Settings
API Enabled: –
Force SSL: –
Currency: USD ($)
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)
Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)
Connected to WooCommerce.com: –
Enforce Approved Product Download Directories: ✔
WC Pages
Shop base: #6 - /index.php/shop/
Cart: #7 - /index.php/cart/
Checkout: #8 - /index.php/checkout/
My account: #9 - /index.php/my-account/
Terms and conditions: ❌ Page not set
Theme
Name: Twenty Twenty-Two
Version: 1.2
Author URL: https://wordpress.org/
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: ✔
Templates
Overrides: –
Admin
Enabled Features: activity-panels
analytics
coupons
customer-effort-score-tracks
experimental-products-task
experimental-import-products-task
experimental-fashion-sample-products
homescreen
marketing
mobile-app-banner
navigation
onboarding
onboarding-tasks
remote-inbox-notifications
remote-free-extensions
payment-gateway-suggestions
shipping-label-banner
subscriptions
store-alerts
transient-notices
wc-pay-promotion
wc-pay-welcome-page
wc-pay-subscriptions-page
Disabled Features: minified-js
settings
Daily Cron: ✔ Next scheduled: 2022-07-12 13:15:21 +00:00
Options: ✔
Notes: 38
Onboarding: -
Action Scheduler
Complete: 2
Oldest: 2022-07-11 13:16:17 +0000
Newest: 2022-07-11 13:16:23 +0000
Pending: 1
Oldest: 2022-07-12 13:16:17 +0000
Newest: 2022-07-12 13:16:17 +0000
Status report information
Generated at: 2022-07-11 13:16:49 +00:00
`
Isolating the problem
Prerequisites
Describe the bug
WooCommerce uses some obsolete code for PHP 8.1
Upon visitting any backoffice page, we can see the errors with the help of Query Monitor plugin.
These are only warnings, however some refactor appears to be required in order to ensure proper PHP 8.1 compatibility and especially to prepare for PHP 8.2 which would probably transform these warnings into errors.
Expected behavior
Running "Query Monitor" extension and, we shouldn't see deprecated functions when using PHP 8.1.
Actual behavior
Many deprecated functions/classes and so on are present.
It is best for a dev to check it directly with Query Monitor, but here are some examples:
Visitting shop's homepage we can see the followings:
Visitting /wp-admin/ shows:
Steps to reproduce
Setup a WordPress with WooCommerce extension, powered by PHP 8.1 on the server.
Install Query Monitor extension.
Check PHP errors and warnings, and see loads of them.
WordPress Environment
PHP 8.1.7
WP 6.0
WooCommerce 6.6.1
`
WordPress Environment
WordPress address (URL): https://woocommercetest.terageek.org
Site address (URL): https://woocommercetest.terageek.org
WC Version: 6.6.1
REST API Version: ✔ 6.6.1
WC Blocks Version: ✔ 7.6.2
Action Scheduler Version: ✔ 3.4.0
Log Directory Writable: ✔
WP Version: 6.0
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: ✔
Language: en_US
External object cache: –
Server Environment
Server Info: Apache
PHP Version: 8.1.7
PHP Post Max Size: 16 MB
PHP Time Limit: 120
PHP Max Input Vars: 1000
cURL Version: 7.74.0
OpenSSL/1.1.1n
SUHOSIN Installed: –
MySQL Version: 10.6.8-MariaDB-1:10.6.8+maria~bullseye
Max Upload Size: 16 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔
Database
WC Database Version: 6.6.1
WC Database Prefix: hJr0qh9_
Total Database Size: 3.81MB
Database Data Size: 2.37MB
Database Index Size: 1.44MB
hJr0qh9_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
hJr0qh9_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
hJr0qh9_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_options: Data: 1.44MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_postmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_posts: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
hJr0qh9_wc_admin_notes: Data: 0.05MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
hJr0qh9_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
hJr0qh9_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
hJr0qh9_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
hJr0qh9_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
hJr0qh9_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
hJr0qh9_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
Post Type Counts
attachment: 1
page: 7
post: 2
Security
Secure connection (HTTPS): ✔
Hide errors from visitors: ✔
Active Plugins (2)
Query Monitor: by John Blackbourn – 3.9.0
WooCommerce: by Automattic – 6.6.1
Inactive Plugins (0)
Dropin Plugins (1)
db.php: Query Monitor Database Class (Drop-in)
Settings
API Enabled: –
Force SSL: –
Currency: USD ($)
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)
Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)
Connected to WooCommerce.com: –
Enforce Approved Product Download Directories: ✔
WC Pages
Shop base: #6 - /index.php/shop/
Cart: #7 - /index.php/cart/
Checkout: #8 - /index.php/checkout/
My account: #9 - /index.php/my-account/
Terms and conditions: ❌ Page not set
Theme
Name: Twenty Twenty-Two
Version: 1.2
Author URL: https://wordpress.org/
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: ✔
Templates
Overrides: –
Admin
Enabled Features: activity-panels
analytics
coupons
customer-effort-score-tracks
experimental-products-task
experimental-import-products-task
experimental-fashion-sample-products
homescreen
marketing
mobile-app-banner
navigation
onboarding
onboarding-tasks
remote-inbox-notifications
remote-free-extensions
payment-gateway-suggestions
shipping-label-banner
subscriptions
store-alerts
transient-notices
wc-pay-promotion
wc-pay-welcome-page
wc-pay-subscriptions-page
Disabled Features: minified-js
settings
Daily Cron: ✔ Next scheduled: 2022-07-12 13:15:21 +00:00
Options: ✔
Notes: 38
Onboarding: -
Action Scheduler
Complete: 2
Oldest: 2022-07-11 13:16:17 +0000
Newest: 2022-07-11 13:16:23 +0000
Pending: 1
Oldest: 2022-07-12 13:16:17 +0000
Newest: 2022-07-12 13:16:17 +0000
Status report information
Generated at: 2022-07-11 13:16:49 +00:00
`
Isolating the problem