Fatal error on line 263 when cookie is empty (count() expects array, null given)
-
Hi there,
We’re using the WC Save for Later plugin, and recently we started getting a fatal PHP error on our cart page:
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given
in /wp-content/plugins/wc-save-for-later/wpc-save-for-later.php on line 263This happens when the cookie used by the plugin is either empty or contains invalid JSON, causing
json_decode()to returnnull.Proposed fix:
In
wpc-save-for-later.php, line 263, replace:
if ( ( $count = count( $products ) ) > 0 ) {with:
if ( is_array( $products ) && ( $count = count( $products ) ) > 0 ) {
This avoids the fatal error and makes the plugin compatible with PHP 7.2+ and PHP 8+.
Thanks in advance and hope this can be included in a future release!
The page I need help with: [log in to see the link]
The topic ‘Fatal error on line 263 when cookie is empty (count() expects array, null given)’ is closed to new replies.