“Trying to access array offset on value of type null” (or bool) in WordPress: what it means and the fix
Short answer
A plugin or theme reads an entry, like $product['price'], from something that isn’t a list at all: null (nothing was found) or false (often a setting that was never saved). PHP gives back nothing and writes this message; the page keeps going. It appeared after the move to PHP 8 because PHP 7.4 called it a notice, which WordPress doesn’t report while WP_DEBUG is off, and PHP 8 made it a warning, which it does. From PHP 8.3 the same message reads “Trying to access array offset on null” or “on false”. Update the plugin or theme; the developer fix is one ?? 'default'.
The message, on three PHP versions
A product box reads a price from a product that wasn’t found (null), and a color from a setting that was never saved (false). The same code on PHP 7.4, 8.0 and 8.3:
wp-content/plugins/product-box/product-box.php
<?php
$product = null; // no product found for this ID
echo 'Price: ', $product['price'], "\n";
$settings = false; // what get_option() returns for a setting never saved
echo 'Color: ', $settings['color'], "\n";
Price:
Notice: Trying to access array offset on value of type null in /var/www/html/wp-content/plugins/product-box/product-box.php on line 3
Color:
Notice: Trying to access array offset on value of type bool in /var/www/html/wp-content/plugins/product-box/product-box.php on line 6Price:
Warning: Trying to access array offset on value of type null in /var/www/html/wp-content/plugins/product-box/product-box.php on line 3
Color:
Warning: Trying to access array offset on value of type bool in /var/www/html/wp-content/plugins/product-box/product-box.php on line 6Price:
Warning: Trying to access array offset on null in /var/www/html/wp-content/plugins/product-box/product-box.php on line 3
Color:
Warning: Trying to access array offset on false in /var/www/html/wp-content/plugins/product-box/product-box.php on line 6Three things change, and none of them stops the page:
- PHP 7.4: a notice.
- PHP 8.0 to 8.2: a warning, same words.
- PHP 8.3 and later: a warning that names the value: “on null”, “on false”.
What it means
$product['price'] asks for the entry price in a list (an array). Here $product isn’t a list: the code expected one, and got nothing. PHP can’t find an entry in nothing, so it returns null and says so. The rest of the page runs normally.
The value is missing at that moment: for this product, this visitor, this setting. On another page, the same line works fine. That’s why the message comes and goes.
Why it appeared after the PHP upgrade
The code didn’t change; the label did. php.net, in the PHP 8.0 changes: “A number of notices have been converted into warnings”, among them “Attempting to access an array index of a non-array.” (php.net)
That matters because of how WordPress reports errors. When WP_DEBUG is off, as it should be on a live site, WordPress reports warnings but not notices (WordPress 7.1.2 source). So on PHP 7.4 the message existed but nobody saw it; on PHP 8 it shows up in the log, or on screen if your host displays PHP warnings.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Update it (Dashboard → Updates): a newer version may already have fixed it.
- Already up to date? Send the full message, with the file and line, to its developer.
- Keep it off your pages meanwhile: log PHP messages instead of showing them, as in the WordPress debug log.
Can a check find it before the upgrade?
Not by reading code: $product['price'] is correct whenever $product is a list, and nothing in the code says when it won’t be. We ran CompatNav’s scanner on the example above: no finding, as expected; it reports only what a code check can be sure of. Your error log is the tool here. On PHP 7.4, set WP_DEBUG and WP_DEBUG_LOG to log notices too, and search the log for “Trying to access array offset”: what you find is what PHP 8 will show. Finding PHP notices on real visits covers doing that on a live site.
Related warnings from the same PHP 8 change: “Undefined array key” and “Attempt to read property on null”.
Key takeaways
- It’s a warning, not a fatal error: the page keeps going, with an empty value where the entry should be.
- PHP 7.4 showed it as a notice, which WordPress doesn’t report unless WP_DEBUG is on; PHP 8.0 made it a warning.
- PHP 8.3 and later word it “Trying to access array offset on null” (or “on false”).
- The cause is a value that’s missing at that moment, so only the error log shows it, not a code check.
- The developer fix:
$value['key'] ?? 'default', which works on every PHP version.
Frequently asked questions
Does this break my site?
No. PHP returns nothing for that entry and carries on. What you may see is an empty spot where the value should be, and the message itself if your host shows PHP warnings on screen.
Why do I see “on value of type bool”?
The variable is false instead of a list. In WordPress that often comes from get_option(), which returns false for a setting that was never saved. PHP 8.3 and later say “on false” instead.
How do I hide it?
Turn off the display of PHP messages and log them instead, as shown in the WordPress debug log guide. That hides it from visitors; the plugin still needs a fix.
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: Backward incompatible changes in PHP 8.0.x
- WordPress 7.1.2 source: wp_debug_mode() (load.php)
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.