Php 8 count products in cart from php cookies not working. Count method not working for me

Viewed 38

I am trying to achieve counting the products added to the cart and this works in php 7 and below but not php 8. Below is the error i get.

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, int given in

Below is my code.

$cookie = isset($_COOKIE['cart_items_cookie']) ? $_COOKIE['cart_items_cookie'] : "";
$cookie = stripslashes($cookie);
$saved_cart_items = json_decode($cookie, true);
$cart_count=count($saved_cart_items);
0 Answers
Related