phanalist

E0052: Unchecked json_decode Result

In plain English: json_decode() returns null when the JSON is invalid. If you immediately read a property or array key from that result, PHP tries to read from null and can fail.

Why it matters: A malformed response or request body can cause a warning, an exception, or a confusing “property on null” error instead of a clear validation message.

Bad

return json_decode($json)->name;
return json_decode($json, true)[0];

Good

$data = json_decode($json, true, flags: JSON_THROW_ON_ERROR);

return $data['name'];

JSON_THROW_ON_ERROR makes invalid JSON throw a JsonException that you can catch. If you do not want exceptions, check the result first:

$data = json_decode($json, true);
if (!is_array($data)) {
    return null;
}

return $data['name'] ?? null;

What the rule checks

It also accepts direct accesses guarded by ??, isset(), or empty(), and calls that use JSON_THROW_ON_ERROR in a positional or named flags argument.

When it does not report

How to fix

Configuration

E0052 has no configuration options and is enabled by default.