count() TypeError after a PHP 8 upgrade
After a PHPPHP is a programming language that builds your web pages on the computer that hosts your site, just before they reach the visitor. WordPress runs on it. 8 upgrade, a page stops with a TypeError at count().
Which PHP version does your site report?
We read only what your site already sends in public: the headers and the top of the homepage. No scan, no login.
More about this
The message may say its argument must be Countable or array, with null given instead.
Start with the value passed to count().
More memory or a different hostingWeb hosting is the service that keeps your website's files on a computer that is always online, so visitors can open your site at any time. plan will not change the meaning of that value.
Before you start
Save the complete error message and its timestamp in a private note. Record which page or action triggers it and what changed immediately beforehand. A screenshot of a blank page gives a developer less to work with than the first relevant log entry.
Do not post passwords, customer information or complete server paths in a public support thread.
Back up both files and the database before changing anything. Check how you would restore that backupA backup is a separate copy of your website's files and database, so you can bring the site back after a mistake, a hack or a failed update. too. Prefer a restricted test copy using the same PHP versionA PHP version is a numbered edition of PHP, like 8.3. Each edition is looked after for a limited time, then gets security fixes only, then nothing..
Disable real payments and outgoing customer emails on that copy. Change one thing per attempt and keep a note of it, so you can reverse an unsuccessful change without guessing what the previous setting was.
What count() expects
count() counts elements in an array or an object implementing Countable. The official PHP documentation records that an invalid type produces a TypeError from PHP 8.0. Earlier versions behaved differently.
Existing code with insufficient input checks can therefore stop after an upgrade even though the feature previously appeared to work.
An array is a collection of values. Null indicates no value, while false may represent a failed operation. These meanings are not interchangeable.
The question is not merely how to prevent the message, but why the expected collection was absent in the first place.
Five steps to a repair
- Save the error line with its file, line number and reported type. Record the page, filter choice or search that triggers it. Note whether it happens only with empty results. Avoid sharing personal search terms or customer details that are unnecessary for the investigation.
- Identify which component calls count(). For a pluginA WordPress plugin is an add-on you install in WordPress to give your site extra features, such as contact forms, SEO tools or a webshop., check available updates and its stated PHP compatibility. For custom code, ask the developer to trace where the value came from. A database query or external integration may have returned a different result earlier in the journey.
- Decide what the application should do with an empty result. An empty list can correctly contain zero items. A failed data request may instead need explicit error handling. Record that distinction before someone adds a fallback to an empty array everywhere.
- Test the targeted code or plugin change on the test copy. Check a normal list, an empty list and a failed request. A type check can help, but must not hide a genuine failure. The chosen repair needs to respect what the data means to the application.
- Verify the result in the interface. Are counts, pagination and empty-result messages correct? Check fresh logs too. Removing the TypeError is only one check; visitors still need correct information when results exist and when they do not.
Why zero is not always the answer
Consider an inventory integration that does not return a response. That is different from a valid response saying there are zero products. Converting every unexpected value into an empty list can lose that distinction.
This example explains why a developer should trace the data flow even when a short type check appears to remove the error.
When to get help
Use the help form below if the count affects inventory, money or reporting, or if several plugins contribute to the value. Provide one successful and one failing action without private data. Ask for tests covering normal, empty and invalid input.
This gives whoever reviews the repair later a way to assess its behaviour rather than relying on a screenshot of a page that loads.
Check the result
Repeat the exact action that failed first. Then check login, a form submission and the main journey through your website. For a store, use a test order without a real charge.
Read the log for fresh messages with a recent timestamp. A working homepage alone does not establish that every affected function works again.
Keep the version numbers, the change and the outcome with your maintenance notes. Agree who will check the next update. Stop if the same error returns after the suspected cause has already been addressed.
Revisit the diagnosis instead of changing an increasing number of settings together. The aim is a repeatable repair that someone else can understand and verify.