Prior to PHP 7.2 using count() on a scalar value or non-countable object would return 1 or 0.
1
0
For example: https://3v4l.org/tGRDE
You can solve it by using "??"-operator. If the left side is null, the right side will be used. So as we have a empty array, our result will be zero.
count(null ?? [])
Another way would be to typecast it as an array.
count((array) null)