If you are on PHP 7.2+, you need to be aware of "Changelog" and use something like this:
<?php
$countFruits = is_array($countFruits) || $countFruits instanceof Countable ? count($countFruits) : 0;
?>
You can organize your code to ensure that the variable is an array, or you can extend the Countable so that you don't have to do this check.