• Resolved Robin Labadie

    (@robin-labadie)


    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 to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello @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 so that our developers can check your report and determine the changes required in future.

    Thank you.

    Thread Starter Robin Labadie

    (@robin-labadie)

    Hello,

    That’s done : https://github.com/woocommerce/woocommerce/issues/33808

    Let’s hope for a fix ??

    Best regards

    Hi @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

    (@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! ??

    diegpl

    (@diegpl)

    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

    (@anastas10s)

    Hi there @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

    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.