"Implicitly marking parameter as nullable is deprecated" in WordPress: what it means and the fix
After a move to PHP 8.4, your log may start filling with lines like "Implicitly marking parameter $value as nullable is deprecated, the explicit nullable type must be used instead". It means some PHP code on your site, such as a plugin or theme, gives a parameter a type and a null default but leaves null out of the type. The fix in that code is small: put a ? in front of the type and keep the default.
If the code isn't yours, don't edit it. Find out which plugin or theme it is, keep the notices off the screen, and report it to the author.
What PHP 8.4 is telling you
PHP 8.4 deprecates implicitly nullable types. The PHP manual describes the old rule: a parameter's type is implicitly widened to accept null if the default value for it is null. That shortcut is what now triggers the notice.
PHP.Watch shows the pattern and the fixes. The first line is the deprecated form. The other two are the replacements.
function test(string $test = null) {}
function test(?string $test = null) {}
function test(string|null $test = null) {}PHP.Watch says both type declarations are effectively equivalent, even at the Reflection API. It also says the suggested replacement works in PHP 7.1 and later.
The catch: the notice fires when PHP reads the declaration, not when the function runs. The RFC says the notice is emitted at compile time, and PHP.Watch adds that it's not emitted when such functions are called. So a line in your log doesn't mean that feature ran.
Is your site broken?
Here's what one site owner saw. In a WordPress.org support thread about this notice in Ninja Tables, a user wrote: "The plugin still works, but PHP generates many deprecation notices in debug mode." The plugin's support team replied that if the plugin is working properly, you can safely continue using it. They added that their development team was already aware of the PHP 8.4 compatibility matter.
The real deadline comes later. The RFC plans to remove support for implicitly nullable types in PHP 9. It also shows how common the pattern is: out of the top 2000 composer packages, 880 use implicitly nullable types. So if one plugin shows up in your log, check the others too.
Keep the notices out of your visitors' view
The Ninja Tables support reply also recommends keeping debug display disabled so these notices aren't shown publicly. WordPress's debugging guide covers the switches. WP_DEBUG_LOG saves all errors to a debug.log file, but it only works when WP_DEBUG is enabled. Setting WP_DEBUG_DISPLAY to false hides all errors, and the guide says to pair it with WP_DEBUG_LOG so you can review the errors later.
These lines come from the guide's example wp-config.php for debugging:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );The same guide says using WP_DEBUG or the other debug tools on live sites is not recommended. Turn it on while you track down the cause, on a staging copy if you have one, then turn it off again.
Find the plugin or theme behind it
The message names the parameter. In the Ninja Tables thread it was $grammar. That name is a good search term. Search your wp-content/plugins and wp-content/themes folders for it, and look for a declaration where a typed parameter has = null and no ? in front of the type.
If you'd rather see everything in one list, our free Bright Labs Compatibility Scanner for PHP is one option. It reads the code of every installed plugin and theme and lists each file and line that uses something removed or deprecated in the PHP version you pick, from PHP 8.2 to 8.5. The scan runs inside WordPress in short steps and doesn't need exec() or shell access.
A clean result isn't a promise, though. The scanner reads code without running it, so it can miss problems in code that's built at runtime and can flag code that never runs. Before a big upgrade, test on a staging copy.
Fix it in code you own
If it's your own plugin, theme or custom code, add the ? and keep the default. PHP.Watch calls this replacement straight-forward and safe. It also says that on class methods, changing implicit nullable parameters to explicit ones is not a backward-compatibility break.
Watch for one case. If the parameter with = null comes before a required parameter, the RFC warns that an optional parameter might now sit before a mandatory one. That causes a second deprecation notice, because optional parameters before required ones were deprecated in PHP 8.0. For that case, the PHP manual's example drops the = null and keeps the nullable type, so the parameter no longer has a default.
In a big codebase you don't have to make every edit by hand. PHP.Watch lists tools that can mark and automatically fix these declarations, and the RFC names two: PHP-CS-Fixer with the nullable_type_declaration_for_default_null_value fixer, and PHP_CodeSniffer. Read the diff before you commit, and run your tests.
When the plugin isn't yours
- Check for an update first, and install it on a staging copy if you can.
- Don't patch the plugin's files on the live site. Report the problem instead.
- Post the exact notice text and your PHP version on the plugin's support forum. The user in the Ninja Tables thread posted their notice there, and the support team answered.
- Keep error display off on the live site while you wait for a fix.
- If the author goes quiet and the plugin matters to your site, keep the planned PHP 9 removal in mind before you upgrade.
Sources
- PHP.Watch article on the implicitly nullable deprecation
- PHP RFC to deprecate implicitly nullable types
- PHP manual list of PHP 8.4 deprecations
- WordPress.org support thread about this notice in Ninja Tables
- WordPress developer guide to debugging
Questions
Will this notice break my WordPress site?
On PHP 8.4 it's a deprecation notice. In the Ninja Tables thread the user said the plugin still worked, and support said that if the plugin works properly you can keep using it. The RFC plans to remove support for implicitly nullable types in PHP 9, so get it fixed or reported before then.
Should I remove the = null default to make the notice go away?
Usually not. The usual fix is to keep the default and put a ? in front of the type. The PHP manual's example drops = null for the case where the parameter sits before a required one.
Why do I see it for a feature I never use?
PHP emits the notice when it compiles the declaration, not when the function is called. So code your site never calls can still trigger it.
How do I stop visitors from seeing these notices?
In wp-config.php, set WP_DEBUG to true, WP_DEBUG_LOG to true and WP_DEBUG_DISPLAY to false. The notices then go to debug.log instead of the page, and you can read them later. Turn debugging off again when you're done on a live site.