“A non-numeric value encountered” in WordPress: what it means on PHP 8
Short answer
It’s a warning: a plugin or theme calculates with text that starts with a number but has something after it, such as “12 left” or “10px”. PHP uses the number and carries on. Its meaning changed with PHP 8.0: on PHP 7 this warning was for text with no number at all; on PHP 8 that case became a fatal error, and this warning took over from the old “non well formed” notice. Update the plugin, or send the message to its developer.
The message, exactly
A shop plugin subtracts a sale from the stock, but the stock was typed as “12 left”. PHP 7.4 gives a notice, PHP 8.0 a warning, and both calculate with 12:
wp-content/plugins/simple-shop/stock.php
<?php
$stock = '12 left'; // a number typed with text after it
echo 'After one sale: ', $stock - 1, "\n";
After one sale:
Notice: A non well formed numeric value encountered in /var/www/html/wp-content/plugins/simple-shop/stock.php on line 3
11After one sale:
Warning: A non-numeric value encountered in /var/www/html/wp-content/plugins/simple-shop/stock.php on line 3
11php.net, on PHP 8.0: “Strings which emitted an E_NOTICE “A non well-formed numeric value encountered” will now emit an E_WARNING “A non-numeric value encountered”” (php.net).
The same words, two meanings
The message is easy to misread across versions, because it moved:
| Text in the calculation | PHP 7.4 | PHP 8.0 and later |
|---|---|---|
| Starts with a number (“12 left”, “10px”) | Notice: “A non well formed numeric value encountered”, uses 12 | Warning: “A non-numeric value encountered”, uses 12 |
| No number at all (“abc”, empty) | Warning: “A non-numeric value encountered”, uses 0 | Fatal error: “Unsupported operand types” |
So if your PHP 7 site showed this warning, the line behind it may stop the page on PHP 8. If your PHP 8 site shows it, the page carries on.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Check its settings for numbers typed with units or words (“10px”, “12 left”, “5 days”) and keep just the number.
- Update it (Dashboard → Updates).
- Still there? Send one full line of the message to its developer.
Warnings shown on a page can break its layout; keep them in a log instead, as shown in the WordPress debug log.
Why no check finds it beforehand
$stock - 1 is correct code; whether $stock holds “12” or “12 left” depends on what was typed on your site. A check that reads code can’t know that, and CompatNav doesn’t report it: its scan of the examples on this page finds nothing.
Key takeaways
- On PHP 8 it’s a warning for text that starts with a number (“12 left”): PHP uses the 12 and carries on.
- On PHP 7.4 the same text gave a quieter notice: “A non well formed numeric value encountered”.
- On PHP 7.4 this warning meant text with no number at all; on PHP 8 that is a fatal error, “Unsupported operand types”.
- It depends on values, such as a setting typed with a unit, so only your error log shows it.
- The fix for developers: convert to a number with
(int)or(float)where the value comes in.
Frequently asked questions
Is it dangerous?
Not by itself: the calculation uses the number at the start of the text. But it often means a setting was typed with a unit or a word, so check that setting too.
My site showed this warning on PHP 7 and now it’s a critical error. Why?
On PHP 7.4 this warning was given for text with no number at all, and PHP calculated with 0. PHP 8.0 turned exactly that case into a fatal error. Our guide to “Unsupported operand types” covers it.
Can I fix it by changing a setting?
Often: if a field like a width or a stock count contains “10px” or “12 left”, entering just the number stops the warning. The plugin should still handle such input, so tell its developer.
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.