Common causes
- A function returned false or null on failure (mysqli_fetch_assoc() after the last row, get_option() for a missing option, json_decode() on invalid JSON)
- A database query found no row, so $row is null or false
- Nested data where an intermediate level is missing ($data['user']['address'])
- Old plugins and themes written before PHP 7.4, which silently returned null here
- Reading from a variable that was never initialized as an array
How to fix it
- Identify the variable being indexed. On the reported line, find the variable before [ and var_dump() it to see whether it is null, false or another scalar.
- Trace where it was set. Find the function call or query that produced it and check its return value on failure in the PHP or WordPress docs.
- Check before indexing. Use is_array($row) or if ($row) before reading keys, or the null coalescing operator: $row['name'] ?? '' works even if $row is null.
- Validate decoded data. After json_decode($json, true), check json_last_error() or use JSON_THROW_ON_ERROR so invalid JSON does not become null silently.
- Update outdated plugins and themes. If the path is inside wp-content/plugins or themes, update that component. This warning is common in code written for PHP 7.3 and older.
- Log instead of display in production. Set WP_DEBUG_DISPLAY to false (or display_errors = Off) and review the log while you fix the code.
PHP
$row = $stmt->fetch(PDO::FETCH_ASSOC); // false if no row
if (!is_array($row)) {
return null;
}
$name = $row['name'];
// or, for nested optional data:
$city = $data['user']['address']['city'] ?? 'Unknown'; How to stop it happening again
- Check return values of functions that can return false or null
- Use ?? for optional nested data
- Decode JSON with JSON_THROW_ON_ERROR