Title: [PHP Obsolete code] PHP 8.1 compatibility
Last modified: July 10, 2022

---

# [PHP Obsolete code] PHP 8.1 compatibility

 *  Resolved [Robin Labadie](https://wordpress.org/support/users/robin-labadie/)
 * (@robin-labadie)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/)
 * WooCommerce uses some obsolete code for PHP 8.1
 * Upon visitting any backoffice page, we can see the following errors with the 
   help of Query Monitor plugin:
 *     ```
       Obsolète	class_exists(): Passing null to parameter #1 ($class) of type string is deprecated	6	
   
           wp-content/plugins/woocommerce/includes/wc-core-functions.php:2050
   
       	Extension : woocommerce
       Obsolète	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	1	
   
           wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_DateTime.php:60
   
       	Extension : woocommerce
       Obsolète	Return type of ActionScheduler_DateTime::getOffset() should either be compatible with DateTime::getOffset(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_DateTime.php:48
   
       	Extension : woocommerce
       Obsolète	Return type of ActionScheduler_DateTime::getTimestamp() should either be compatible with DateTime::getTimestamp(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_DateTime.php:27
   
       	Extension : woocommerce
       Obsolète	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	1	
   
           wp-includes/Requests/Utility/CaseInsensitiveDictionary.php:40
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Utility/CaseInsensitiveDictionary.php:51
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Utility/CaseInsensitiveDictionary.php:68
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Utility/CaseInsensitiveDictionary.php:82
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Utility/CaseInsensitiveDictionary.php:91
   
       	Extension : woocommerce
       Obsolète	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	1	
   
           wp-includes/Requests/Cookie/Jar.php:63
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Cookie/Jar.php:73
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Cookie/Jar.php:89
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Cookie/Jar.php:102
   
       	Extension : woocommerce
       Obsolète	Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice	1	
   
           wp-includes/Requests/Cookie/Jar.php:111
   
       	Extension : woocommerce
       Obsolète	explode(): Passing null to parameter #2 ($string) of type string is deprecated	1	
   
           wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php:371
   
       	Extension : woocommerce
       Obsolète	parse_str(): Passing null to parameter #1 ($string) of type string is deprecated	1	
   
           wp-content/plugins/woocommerce/src/Admin/PageController.php:128
   
       	Extension : woocommerce
       ```
   
 * 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.
 * Best regards
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-obsolete-code-php-8-1-compatibility%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Rashed Ripon (a11n)](https://wordpress.org/support/users/rur165/)
 * (@rur165)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/#post-15814555)
 * Hello [@robin-labadie](https://wordpress.org/support/users/robin-labadie/) ,
 * Thanks a lot for sharing the concerns regarding the latest PHP compatibility 
   with WooCommerce.
 * It would be best if you can submit the request directly on [WooCommerce’s GitHub repository](https://github.com/woocommerce/woocommerce/issues/new/choose)
   so that our developers can check your report and determine the changes required
   in future.
 * Thank you.
 *  Thread Starter [Robin Labadie](https://wordpress.org/support/users/robin-labadie/)
 * (@robin-labadie)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/#post-15815550)
 * Hello,
 * That’s done : [https://github.com/woocommerce/woocommerce/issues/33808](https://github.com/woocommerce/woocommerce/issues/33808)
 * Let’s hope for a fix 🙂
 * Best regards
 *  [Mike W](https://wordpress.org/support/users/nixiack8/)
 * (@nixiack8)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/#post-15816527)
 * Hi [@robin-labadie](https://wordpress.org/support/users/robin-labadie/),
 * Thank you for that! As it is a public repository, watch that thread that was 
   created for the fix – the developers should be able to chime in on it.
 * If/when a PR (Push Request) is done for it, then it will most likely be in the
   next release.
 * Cheers!
 *  [diegpl](https://wordpress.org/support/users/diegpl/)
 * (@diegpl)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/#post-16130255)
 * Hmm, no fixing yet? This turned my server way slower than previously bcz of the
   errors logs, which I needed to turn off. Any news about the fixing date? That
   is kinda odd, to have been fixed yet. Tks! 😉
 *  [diegpl](https://wordpress.org/support/users/diegpl/)
 * (@diegpl)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/#post-16130264)
 * If we set an empty valye for $date_string instead of null, could that fix some
   errors?
 *     ```
       function as_get_datetime_object( $date_string = '', $timezone = 'UTC' ) {
       	if ( is_object( $date_string ) && $date_string instanceof DateTime ) {
       		$date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) );
       	} elseif ( is_numeric( $date_string ) ) {
       		$date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) );
       	} else {
       		$date = new ActionScheduler_DateTime( '' === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) );
       	}
       	return $date;
       }
       ```
   
 * instead of:
 *     ```
       function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) {
       	if ( is_object( $date_string ) && $date_string instanceof DateTime ) {
       		$date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) );
       	} elseif ( is_numeric( $date_string ) ) {
       		$date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) );
       	} else {
       		$date = new ActionScheduler_DateTime( null === $date_string ? 'now' : $date_string, new DateTimeZone( $timezone ) );
       	}
       	return $date;
       }
       ```
   
 *  [anastas10s](https://wordpress.org/support/users/anastas10s/)
 * (@anastas10s)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/#post-16132549)
 * Hi there [@diegpl](https://wordpress.org/support/users/diegpl/) 👋
 * > Hmm, no fixing yet? This turned my server way slower than previously bcz of
   > the errors logs, which I needed to turn off. Any news about the fixing date?
   > That is kinda odd, to have been fixed yet. Tks! 😉
 * +
 * > If we set an empty valye for $date_string instead of null, could that fix some
   > errors?
 * Thanks a lot for sharing the concerns regarding the latest PHP compatibility 
   with WooCommerce.
 * Feel free to add them in the related GitHub issue, here:
    [https://github.com/woocommerce/woocommerce/issues/33808](https://github.com/woocommerce/woocommerce/issues/33808)
 * That way, our developers can check your report and determine the changes required
   in the future.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘[PHP Obsolete code] PHP 8.1 compatibility’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [PHP compatibility](https://wordpress.org/support/topic-tag/php-compatibility/)

 * 6 replies
 * 5 participants
 * Last reply from: [anastas10s](https://wordpress.org/support/users/anastas10s/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/php-obsolete-code-php-8-1-compatibility/#post-16132549)
 * Status: resolved