“Unsupported operand types: string * float” in WordPress: why PHP 8 stops, and the fix
Short answer
It’s a fatal error from PHP 8.0 and later: a plugin or theme does arithmetic with text that isn’t a number at all, most often an empty value, such as a price or quantity that was never saved. PHP 7 printed a warning (“A non-numeric value encountered”) and used 0; PHP 8 stops the page, so WordPress shows “There has been a critical error on this website”. It depends on your data, so no code check can see it beforehand. Update the plugin, or send the message to its developer.
The message, exactly
A shop plugin adds tax to a price, but this product has no price saved: the value is empty text. PHP 7.4 warns and calculates with 0; PHP 8.0 stops:
wp-content/plugins/simple-shop/price.php
<?php
$price = ''; // like get_post_meta() when no price was saved
echo 'With tax: ', $price * 1.2, "\n";
With tax:
Warning: A non-numeric value encountered in /var/www/html/wp-content/plugins/simple-shop/price.php on line 3
0With tax:
Fatal error: Uncaught TypeError: Unsupported operand types: string * float in /var/www/html/wp-content/plugins/simple-shop/price.php:3
Stack trace:
#0 {main}
thrown in /var/www/html/wp-content/plugins/simple-shop/price.php on line 3The two words around the operator name the types involved: string * float is text multiplied by a decimal number; string + int is text plus a whole number; string + string means both sides are text.
What changed in PHP 8.0
php.net, on how PHP 8.0 treats text in calculations: “Strings which emitted an E_NOTICE “A non well-formed numeric value encountered” will now emit an E_WARNING “A non-numeric value encountered” and all strings which emitted an E_WARNING “A non-numeric value encountered” will now throw a TypeError.” (php.net)
So there are two cases:
- Text with no number at all (including an empty value): a warning on PHP 7, a fatal error on PHP 8. That’s this page.
- Text that starts with a number, such as “12 left”: a notice on PHP 7, a warning on PHP 8, and the number is used. That case is explained in “A non-numeric value encountered”.
Fix it, in order
- Site down? Switch PHP back in your hosting panel, or pause the plugin through the link in WordPress’s email. The critical error guide shows both.
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Look for the empty value: the page that broke usually has a field left blank (a price, a quantity, a width). Filling it in brings that page back.
- Update the plugin (Dashboard → Updates), or send the full message to its developer: the code must handle empty values.
Why no check finds it beforehand
$price * 1.2 is correct code as long as $price holds a number. Whether it does depends on what is saved for each product, so a check that reads code can’t know. CompatNav doesn’t report it; its scan of the examples on this page finds nothing. Watch your error log for a few days after a PHP switch: the WordPress debug log shows how to keep one.
Key takeaways
- Since PHP 8.0, arithmetic with text that isn’t a number throws a TypeError and stops the page.
- On PHP 7.4 the same line only gave the warning “A non-numeric value encountered” and counted the text as 0.
- The message names the types:
string * floatmeans text multiplied by a decimal number. An empty setting is the usual culprit. - Text that starts with a number (“12 left”) only gives a warning on PHP 8; text with no number at all stops the page.
- It depends on values, so only your error log shows it. The fix for developers: convert to a number first.
Frequently asked questions
Why did this start after the PHP update?
PHP 8.0 changed the rule: what PHP 7 reported as “A non-numeric value encountered” and calculated with 0 is now a TypeError. The code was already doing arithmetic with an empty value; PHP 8 stops instead of guessing.
Why does it only happen on some products or pages?
Because it depends on the data: a product with a price works, one without a price stops the page. Filling in the missing value is a quick workaround while the plugin is fixed.
What is the difference with “A non-numeric value encountered”?
On PHP 8 that warning is for text that starts with a number, such as “12 left”: PHP uses the 12 and warns. Text with no number at all, including an empty value, is the fatal error on this page.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.