Warning: Trying to access array offset on value of type null
Code used $x['key'] where $x is null — usually a lookup or function that returned nothing.
Seen on:
PHP
Meaning
PHP 7.4+ warns when you index into null, bool or int. The variable you think is an array is actually null because a query returned no row, a function returned null, or a key was missing.
Common causes
- Database fetch returned no row (
fetch()→ false/null) - Function returned null on failure
- json_decode failed and returned null
- Nested array key missing one level up
⚡ Quick fix
- Check the value before indexing
- Use the null coalescing operator:
$row['name'] ?? '' - Handle "not found" explicitly
Detailed fix by platform
PHP
$user = $st->fetch(); if (!$user) { http_response_code(404); exit; }
How to diagnose
- Variable — Which variable is null?
- Source — What returned it — query, function, JSON?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026