php 8.4 bug
-
Hello,
I would like to report a compatibility issue that appears to affect your plugin when running on PHP 8.4.
Environment
- WordPress: 7.0.2
- WooCommerce: Latest version
- PHP: 8.4
- Theme: Woodmart 8.5.5
Problem
A fatal error occurs while updating the WooCommerce cart via AJAX.
The error is:
Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, false givenFile:
wp-content/plugins/woo-min-max-quantity-step-control-single/includes/min-max-controller.phpLine:
987Backtrace:
#0 .../min-max-controller.php(987): method_exists(false, 'is_sold_individually') #1 .../class-wp-hook.php(341): WC_MMQ\Includes\Min_Max_Controller->update_cart_validation(...) #2 .../plugin.php(205): WP_Hook->apply_filters(...) #3 .../woodmart/inc/integrations/woocommerce/modules/quantity.php(62): apply_filters('woocommerce_update_cart_validation', ...) #4 .../class-wp-hook.php(341): woodmart_update_cart_item('') #5 .../plugin.php(522): WP_Hook->do_action(...) #6 .../wp-admin/admin-ajax.php(207): do_action(...)Cause
It appears that
wc_get_product( $product_id )can returnfalsein some situations. However, the plugin immediately calls:method_exists( $this->product, 'is_sold_individually' )When
$this->productisfalse, PHP 8.4 throws a fatalTypeError.This seems to be caused by a missing validation before calling
method_exists()or other product methods.Suggested Fix
Before calling any product methods, please verify that the returned value is a valid
WC_Productobject. For example:$this->product = wc_get_product( $product_id ); if ( ! $this->product instanceof WC_Product ) { return $bool; } if ( $this->product->is_sold_individually() ) { return $bool; }or use another equivalent validation that ensures
$this->productis a valid object before accessing its methods.I believe this is a compatibility issue with newer PHP versions rather than WooCommerce itself.
Thank you for your work on the plugin. I hope this issue can be addressed in a future update.
You must be logged in to reply to this topic.