Upgravo › Guides

"Uncaught TypeError: … must be of type …" – why PHP 8 turns old warnings into fatal errors

Last reviewed 8 November 2026 · by Nicolás Alejandro Salinas

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

  1. Open wp-content/debug.log or the host's PHP error log. The fatal error is logged even when the screen only says "critical error".
  2. The first line of the stack trace that contains /wp-content/plugins/ is the plugin; the line number is where the bad call is.
  3. Update that plugin. Most TypeErrors in popular plugins were fixed in 2021-2022, in the months after PHP 8.0.
  4. 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.
  5. 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:

  1. Create a staging copy (most hosts offer one; Local, by WP Engine, works for a copy on your own computer).
  2. Switch the staging copy to the target PHP version.
  3. Turn on WP_DEBUG and WP_DEBUG_LOG, then click through the parts of the site that matter: admin screens of each plugin, checkout, forms, the pages that use shortcodes.
  4. Read the log. A TypeError names 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

Sources

More guides