"Uncaught TypeError: … must be of type …" – why PHP 8 turns old warnings into fatal errors
This is a fatal error, not a notice. The page stops at that line and WordPress shows "There has been a critical error on this website". It appears after a move from PHP 7.x to PHP 8.x, and it is not caused by a new rule: the code was always wrong, PHP 7 just tolerated it.
What the message looks like
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type
Countable|array, string given in /wp-content/plugins/some-plugin/util.php:663
Other common shapes of the same error:
array_merge(): Argument #2 must be of type array, null given
strpos(): Argument #1 ($haystack) must be of type string, array given
array_filter(): Argument #1 ($array) must be of type array, string given
fclose(): Argument #1 ($stream) must be of type resource, bool given
The path names the plugin. The function named at the start (count, array_merge, strpos…) is a built-in PHP function that received the wrong kind of value.
Why PHP 8 started failing
PHP 7 was lenient with built-in functions. Pass a string to count() and you got a warning and the value 1; pass null to array_merge() and you got a warning and an empty result. The code limped on and nobody noticed.
PHP 8.0 made built-in functions strict: a wrong argument type throws a TypeError. The warning became a crash. Typical code that triggers it:
$items = get_option( 'some_plugin_items' ); // false the first time, array later
echo count( $items ); // PHP 7: warning, prints 1. PHP 8: fatal.
The fix is to check the value before using it:
$items = get_option( 'some_plugin_items', array() );
echo count( (array) $items );
Because the error depends on the value at runtime (an option that is false the first time, a meta field that was never saved), it often appears on one site and not another with the same plugin.
How to find the plugin responsible
- Open
wp-content/debug.logor the host's PHP error log. The fatal error is logged even when the screen only says "critical error". - The first line of the stack trace that contains
/wp-content/plugins/is the plugin; the line number is where the bad call is. - Update that plugin. Most TypeErrors in popular plugins were fixed in 2021-2022, in the months after PHP 8.0.
- If the error persists after updating, open the plugin's support forum on WordPress.org with the first three lines of the error. This class of bug is easy to fix for the author once they see the line.
- If the author does not respond and the plugin has not been updated since 2022, replace it.
Can a scanner find this before you upgrade?
Partly, and it is worth being clear about which part.
A static scanner (one that reads the code without running it) cannot know that get_option() will return false on your site. So it cannot promise to find every TypeError. What it can find reliably is the other half of PHP 8 breakage: functions removed in PHP 8 (each(), create_function(), money_format()), parameters whose order or meaning changed (implode() with reversed arguments), and constants that no longer exist. Those are fatal on PHP 8 too, and they do not depend on runtime values.
Upgravo scans the code of all installed plugins and themes against the PHP version you choose and lists those removed functions, changed parameters and constants per plugin, file and line. It does not claim to catch TypeErrors caused by runtime values, and its report says so.
Install it from WordPress.org: Upgravo – PHP Compatibility Check. The scan runs on your own server; no code is sent anywhere.
The safe way to test for TypeErrors
Since this error depends on data, the reliable test is to run the site on PHP 8 before the live switch:
- Create a staging copy (most hosts offer one; Local, by WP Engine, works for a copy on your own computer).
- Switch the staging copy to the target PHP version.
- Turn on
WP_DEBUGandWP_DEBUG_LOG, then click through the parts of the site that matter: admin screens of each plugin, checkout, forms, the pages that use shortcodes. - Read the log. A
TypeErrornames the plugin and the line.
Ten minutes of clicking on staging finds the TypeErrors that no scanner can.
If the plugin author won't fix it
- Revert to the previous PHP version on the live site. This is the one case where that is the right first move: the site is down.
- Patch locally only if you can read PHP: cast or check the value before the call (
(array) $x,is_array( $x )). The next plugin update overwrites your change. - Replace the plugin. A plugin that crashes on PHP 8 in 2026 has been unmaintained for four years.
Sources
- PHP RFC: Consistent type errors for internal functions
- PHP 8.0 migration guide, backward incompatible changes
- Support threads: Urvanov Syntax Highlighter, Meta Box, WPML, 2021-2024
More guides
- "Deprecated: Creation of dynamic property" in WordPress – what it means and how to fix it
- "Implicitly marking parameter as nullable is deprecated" – PHP 8.4 and WordPress plugins
- "There has been a critical error on this website" after a PHP update
- PHP Compatibility Checker is abandoned – what to use instead
- WordPress debug.log full of "Deprecated" notices – should you worry?
- My host forced a PHP upgrade and broke my WordPress site
- How to check if your WordPress plugins are compatible with PHP 8.3 or 8.4 before upgrading
- PHP 7.4 is end of life: what breaks in WordPress when you move to PHP 8