What changes were made in PHP 7.2 that led to the warning being thrown when count() is used on non-array or non-Countable objects?

In PHP 7.2, changes were made to the count() function to throw a warning when used on non-array or non-Countable objects to prevent potential errors. To solve this issue, you can check if the variable is an array or implements the Countable interface before using count().

if (is_array($variable) || $variable instanceof Countable) {
    $count = count($variable);
} else {
    $count = 0;
}