count() Must Count Countable
PHP used to count any kind of value. Most values would then be counted as one. This is not possible anymore in PHP 8.0. It requires an array or a countable object. This can be tested with is_countable.
PHP code
<?php
print count(3);
?>
Before
PHP Warning: count(): Parameter must be an array or an object that implements Countable
Warning: count(): Parameter must be an array or an object that implements Countable
1
After
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, int given
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, int given
PHP version change
This behavior was deprecated in 7.2.
This behavior changed in 8.0.