Warning: count(): Parameter must be an array or a

HI
How are you all?

I get the following error when clicking on a product to view from the main front page.

Warning: count(): Parameter must be an array or an object that implements Countable in ~/pages/product.inc.php (Line 12)

This is the code from around line 12 - 12 is 2nd line down
if (empty($_GET['category_id']) && empty($product->manufacturer)) {
    if (count($product->category_ids)) {
      $category_ids = array_values($product->category_ids);
      $_GET['category_id'] = array_shift($category_ids);
    }
  }

Server stats 
php 7.2.5
apache 2.4
freebsd 11.1
mysql  Ver 14.14 Distrib 5.6.40, for FreeBSD11.1 (amd64) 
litecart 2.1.2

This doesn't happen on all products, only on products that are in 2 categories. my categories were nested. 
SO i had "clothing>>Tshirts-Product, tshirt was checked for both clothing and t shirts.

If i remove the product from one of the categories then its ok.
While i'm not too fussed about this issue as im only making this site for a small biker community to sell club badges and clothing,
 I just removed all the categories and have now only products. this may affect very large stores with thousands of products and categories.

A quick google search suggest this is a php 7.2 issue.

edit to add - The app throws this error also when the product is in no category (ROOT) To avoid this error i had to just create 1 category and attach all my products to that 1 category.

Thanks
Peter
tim
Can you debug and see what's returned by this? Do all products have a default_category_id ?

var_dump($product->category_ids);
HI
thanks for the reply, when i run that under the database for the store in phpmyadmin, sql tab i get the below

Error
Static analysis:

5 errors were found during analysis.

Unexpected character. (near "$" at position 9)
Unexpected beginning of statement. (near "var_dump" at position 0)
Unexpected beginning of statement. (near "$" at position 9)
Unexpected beginning of statement. (near "product" at position 10)
Unexpected beginning of statement. (near "category_ids" at position 19)
SO i tried to replicate this issue and now it not doing it. I cant seem to replicate it, weird. being a new server setup and adding modules as needed maybe an module added for something else has fixed this issue without realising. not sure.

if it happens again i will report back here.
Thanks anyway :)

Peter