phanalist

E0051: Count of a Non-Countable Value

In plain English: count() works on arrays and on objects that implement Countable. Passing a string, number, boolean, or null is an error in PHP 8.

Why it matters: The code throws a TypeError instead of returning a length, so the request or job can fail at runtime.

Bad

count('hello'); // TypeError
sizeof(42);     // TypeError
count(null);    // TypeError

Good

count($items);      // $items is an array
sizeof($collection); // $collection implements Countable
strlen($text);      // use strlen() for strings

What the rule checks

When it does not report

How to fix

Configuration

E0051 has no configuration options and is enabled by default.