Automattic / woocommerce-subscriptions-core

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

Make `WCS_Array_Property_Post_Meta_Black_Magic` PHP 8.1 compatible #503

Closed the-csaba closed 12 months ago

the-csaba commented 1 year ago

Fixes #436

Description

This update adds the ReturnTypeWillChange attribute to methods in the WCS_Array_Property_Post_Meta_Black_Magic class. This change will make ArrayAccess implementations compatible with PHP 8.1 and above. By using the attribute instead of changing the method signatures, we can maintain compatibility with older PHP versions (i.e., PHP 7.x).

As developers of the WooCommerce Zapier plugin, which adds Zapier integration to Subscriptions, we have a vested interest in ensuring that our code and tests are compatible with newer PHP versions.

By design, adding this attribute will appear like a comment in older PHP versions, so we do not anticipate any code-breaking changes.

Without this change, in PHP 8.1, if you try to create Variable Subscriptions, a deprecation notice occurs:

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 woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 65

How to Test This PR

  1. Use PHP 8.1.
  2. Enable WP_DEBUG and WP_DEBUG_DISPLAY
  3. Create a subscription product.
  4. Observe the deprecated message.

Product Impact

gsim commented 8 months ago

2024 now... errors also show on product list mage, making it almost unusable. busy deloping new site (to replace current site) so php errors are enabled, and this makes it a nightmare. How's it closed? Am I missing somthing? Plugin is up to date.

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 /var/www/pnp/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 65

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 /var/www/pnp/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 47

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 /var/www/pnp/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 56

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 /var/www/pnp/wp-content/plugins/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/legacy/class-wcs-array-property-post-meta-black-magic.php on line 72

mattallan commented 8 months ago

@gsim what version of the main Woo Subscriptions extension do you have running on your store? The issue you're seeing was fixed in version 5.6.0.