“Using null as an array offset is deprecated” in WordPress: PHP 8.5 explained
Short answer
It’s a deprecation notice from PHP 8.5: a plugin or theme uses null as the key of a list entry. PHP turns that null into an empty key; PHP 8.5 still does, but now asks for an empty string written out. The code keeps working. When the null is written in the code, a check that reads code finds it; when it comes from a value that happens to be empty, only your error log shows it. Update the plugin, or send the message to its developer.
The message, exactly
A menu plugin stores a label under a null key. PHP 8.4 runs it silently; PHP 8.5 adds the notice and names the fix:
wp-content/plugins/menu-labels/menu-labels.php
<?php
$labels = [];
$labels[null] = 'Home';
echo count($labels), ' label, key: "', array_key_first($labels), '"', "\n";
1 label, key: ""Deprecated: Using null as an array offset is deprecated, use an empty string instead in /var/www/html/wp-content/plugins/menu-labels/menu-labels.php on line 3
1 label, key: ""Both versions store the label under an empty key "". php.net: “Using null as an array offset or when calling array_key_exists() is now deprecated. Instead an empty string should be used.” (php.net)
When the null comes from a value
More often, nobody wrote null in the code: the key comes from a value that happens to be empty, such as a setting that was never saved. PHP 8.5 reports that too:
wp-content/plugins/menu-labels/menu-labels.php
<?php
function saved_menu_slug() {
return null; // nothing saved yet
}
$labels = [];
$labels[saved_menu_slug()] = 'Home';
echo count($labels), ' label', "\n";
1 labelDeprecated: Using null as an array offset is deprecated, use an empty string instead in /var/www/html/wp-content/plugins/menu-labels/menu-labels.php on line 7
1 labelA check that reads code sees $labels[saved_menu_slug()], not what that function returns on your site. CompatNav reports the first example, where null is written in the code, and not this one: its scan finds nothing here. Your error log is where the second kind shows up; the WordPress debug log shows how to keep one without displaying messages to visitors.
Is it urgent?
No. The result is the same as on PHP 8.4. It needs fixing at some point, because a future PHP version is expected to change what is deprecated today, and a busy plugin can write this notice on every page view.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Update it (Dashboard → Updates): its developer may already have fixed it.
- Already on the latest version? Send one full line of the message to its developer.
The null written in the code is found before you switch, while your site still runs PHP 8.4:
The other PHP 8.5 changes, including the three that can stop code, are in WordPress and PHP 8.5.
Key takeaways
- It’s a deprecation notice from PHP 8.5; the result is the same as before.
- PHP turns a
nullkey into an empty key"", and from 8.5 asks for""to be written explicitly. - It also applies to
array_key_exists()withnull. - When
nullcomes from a variable, the notice depends on values: only your error log shows it. - The fix for developers: use
''instead ofnull, or?? ''where the key comes from a value.
Frequently asked questions
Is it dangerous?
No. PHP 8.5 gives the same result as PHP 8.4; it only adds the notice. A future PHP version is expected to change it further, so the plugin should be updated.
Why does a compatibility check miss some of them?
A check that reads code sees $labels[null], but not that $labels[$slug] will receive null on your site. The second kind shows up only while the site runs, in your error log.
Is WordPress itself ready for PHP 8.5?
Yes, WordPress 6.9 and later are compatible with PHP 8.5. This notice comes from plugin or theme code; our PHP 8.5 guide lists the other changes.
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
- php.net: Deprecated features in PHP 8.5.x
- make.wordpress.org: PHP Compatibility and WordPress Versions
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.