How to fix common PHP 8.4 deprecation notices in WordPress
Short answer
PHP 8.4’s deprecation notices don’t stop your pages: each one is a line that starts with “Deprecated:”, written to the log or, if your host shows PHP messages, onto the page. Fix them in four steps: keep them off your pages by logging instead of displaying, group them by plugin or theme (the path in each message names it), update what has an update, and send the rest to the developers. For developers, every common PHP 8.4 notice has a short fix; the most common one, a parameter like string $note = null, becomes ?string $note = null.
First: is it really a deprecation notice?
Look at the first word of the message:
- “Deprecated:” The page works. Everything on this page applies.
- “Fatal error:” The page stops. On PHP 8.4 that’s usually one of five removed MySQLi constants or a missing extension such as IMAP; start with the critical error guide.
For the difference in general: deprecation notice or fatal error.
Step 1: keep them off your pages
Notices printed on a page look broken to visitors, and they can break redirects and logins (why). WordPress already leaves them out while WP_DEBUG is off: it reports errors and warnings, not deprecation notices (WordPress 7.1.2 source). If you see them anyway, either WP_DEBUG is on, or your host displays every PHP message.
To fix them, you want them in a log, not on the page: the WordPress debug log has the three lines for wp-config.php. Do it on a staging copy if you can.
Step 2: group them by plugin or theme
Every notice ends with a path such as wp-content/plugins/order-notes/order-notes.php. The folder after plugins/ or themes/ is the one responsible. Sort your log by that folder: a long log may come from only one or two plugins.
A check that reads code gives you the same list without waiting for visits. CompatNav, a free plugin on wordpress.org, lists the PHP 8.4 deprecation notices per plugin and theme, with file and line, on your own server:
Step 3: update
Dashboard → Updates. Maintained plugins and themes fix these notices over time, so an update may clear a whole group at once. Check the log again afterwards.
Step 4: send the rest to the developers
For each remaining group, send the developer one full line of the notice: the message, the file and the line. Contacting the author has a message you can adapt. Don’t edit a plugin’s files yourself: the next update overwrites them.
For developers: the fix for each notice
The PHP 8.4 notices you’re most likely to meet, as PHP writes them, with the change that removes each. Each fix is tested on the official PHP builds, with full examples in WordPress and PHP 8.4:
| The notice starts with | The fix |
|---|---|
Implicitly marking parameter $… as nullable is deprecated | Write the type as nullable: ?string $note = null (details) |
Constant E_STRICT is deprecated | Remove E_STRICT from the error level (details) |
Passing E_USER_ERROR to trigger_error() is deprecated since 8.4 | Throw an exception, or call exit() with the message |
fputcsv(): the $escape parameter must be provided as its default value will change | Pass the escape argument explicitly, for example '' or '\\' |
Function lcg_value() is deprecated since 8.4 | mt_rand() / mt_getrandmax(), or on PHP 8.3 and later \Random\Randomizer::getFloat(), as the message suggests |
session_set_save_handler(): Providing individual callbacks … is deprecated | Pass an object that implements SessionHandlerInterface |
Using "_" as a class name is deprecated since 8.4 | Rename the class |
Return type of … should either be compatible with … | Declare the return type, or add #[\ReturnTypeWillChange] (details) |
The most common one, side by side. A parameter made nullable only by its = null default gets a notice on PHP 8.4:
wp-content/plugins/order-notes/order-notes.php
<?php
class Order_Note {
public function __construct(string $text, DateTime $created = null) {
echo $text, $created ? ' (dated)' : ' (no date)', "\n";
}
}
new Order_Note('Gift wrap');
Gift wrap (no date)Deprecated: Order_Note::__construct(): Implicitly marking parameter $created as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/wp-content/plugins/order-notes/order-notes.php on line 3
Gift wrap (no date)The explicit ? removes it, and works on PHP 7.1 and later:
wp-content/plugins/order-notes/order-notes.php
<?php
class Order_Note {
public function __construct(string $text, ?DateTime $created = null) {
echo $text, $created ? ' (dated)' : ' (no date)', "\n";
}
}
new Order_Note('Gift wrap');
Gift wrap (no date)Gift wrap (no date)Gift wrap (no date)Before the next upgrade
Deprecation notices are PHP announcing what it plans to change. Checking for the next version before you switch shows them while there’s time: preparing for PHP 8.4 has the full checklist, and the PHP 8.4 compatibility checker what a check covers.
Key takeaways
- A line starting with “Deprecated:” never stops a page; a line starting with “Fatal error:” does, and needs fixing first.
- Step 1: log PHP messages instead of displaying them, so visitors don’t see them and redirects keep working.
- Step 2: group the notices by the plugin or theme in their path; one update often clears many lines.
- Step 3 and 4: update what you can, and send one line of each remaining notice to its developer.
- The developer fixes are short; the table below has one per notice, each tested on the official PHP builds.
Frequently asked questions
Do I have to fix PHP 8.4 deprecation notices?
Not before switching: your site works with them. They mark code that a later PHP version may stop accepting, so they should be fixed over time, mostly through plugin and theme updates.
Why do I see dozens of the same notice?
Some notices appear each time a file is loaded, on every page. A single parameter written the old way can fill a log. Group by file and line: it’s usually one place.
Can I just turn deprecation notices off?
On a live site, yes: with WP_DEBUG off, WordPress doesn’t report them at all. Keep a debug log on a staging copy, so you still know what needs fixing.
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.