PHP 8.5 deprecates using null as an array offset and passing it to array_key_exists(). Decide what null means before accessing the array. Reject a missing key, skip the operation, or normalize it to an intentional string value.
Last updated: October 7, 2026.
<?php
declare(strict_types=1);
function incrementCount(array &$counts, ?string $key): void
{
if ($key === null) {
throw new InvalidArgumentException('A count key is required.');
}
$counts[$key] = ($counts[$key] ?? 0) + 1;
}
$counts = [];
incrementCount($counts, 'completed');
// If the empty string is a real business key, normalize explicitly:
$nullableKey = null;
$normalizedKey = $nullableKey ?? '';
$exists = array_key_exists($normalizedKey, $counts);The explicit check preserves the distinction between “missing” and an empty-string key. Although older PHP versions silently converted a null key to an empty string, relying on that coercion can merge unrelated data and hide an upstream validation problem.
Find both access and existence checks
Search for nullable values used in $array[$key], assignments, isset() expressions, and array_key_exists($key, $array). Static analysis can narrow the search when the key type is ?string or otherwise includes null. Add tests for the null path instead of merely suppressing E_DEPRECATED.
The PHP 8.5 deprecated-features guide states that null array offsets and null keys passed to array_key_exists() are deprecated and recommends an empty string when that is truly the intended key.
Normalize at the application boundary
If a request field, decoded JSON property, or database column supplies the key, validate it where that data enters the application. This keeps internal functions on a clear string contract. Use an explicit sentinel such as unknown only when the data model defines it, not as a universal substitute for missing input.
During an upgrade, run the test suite with deprecations visible and capture production deprecations in logs before PHP eventually promotes the behavior. Do not display those notices to users. The PHP 8.5 release announcement summarizes this compatibility change. Continue with PHP arrays, PHP function parameters, and debugging PHP with Xdebug.