Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
87 stars 33 forks source link

WCS_Array_Property_Post_Meta_Black_Magic implements ArrayAccess and is throwing deprecation warnings with PHP 8.1 #436

Closed mattallan closed 1 year ago

mattallan commented 1 year ago

Reported internally: p1683089718053349-slack-C7U3Y3VMY

Describe the bug

A merchant running the latest WooCommerce Subscriptions and PHP 8.1 has reported the following logs:

[01-May-2023 05:32:43 UTC] PHP Deprecated:  Return type of WCS_Array_Property_Post_Meta_Black_Magic::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /bitnami/wordpress/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 65
[01-May-2023 05:32:43 UTC] PHP Deprecated:  Return type of WCS_Array_Property_Post_Meta_Black_Magic::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /bitnami/wordpress/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 47
[01-May-2023 05:32:43 UTC] PHP Deprecated:  Return type of WCS_Array_Property_Post_Meta_Black_Magic::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 in /bitnami/wordpress/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 56
[01-May-2023 05:32:43 UTC] PHP Deprecated:  Return type of WCS_Array_Property_Post_Meta_Black_Magic::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /bitnami/wordpress/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 72

I'm not familiar with the proper way of fixing these but I did notice WooCommerce Core addressed similar issues by adding #[\ReturnTypeWillChange] to the line above the function call.

For example:

/**
 * offsetExists
 * @param string $key
 * @return bool
 */
#[\ReturnTypeWillChange]
public function offsetExists( $key ) {
    return metadata_exists( 'post', $this->product_id, $this->maybe_prefix_meta_key( $key ) );
}

See their commit: https://github.com/woocommerce/woocommerce/commit/963eef02fa3c96762233ed0a93634d1a1eb559a4#diff-c71a0e842a830b116fa6f816a341df210799f54b88c8dd9c02420fffc635e37d

lynnjat7 commented 1 year ago

6572982-zen

solstudioim commented 1 year ago

A different merchant seeing a similar issue here: 6732938-zd-a8c

Deprecated: Return type of WCS_Array_Property_Post_Meta_Black_Magic::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /bitnami/wordpress/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 72