Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead¶
Description¶
null cannot be used as an array index anymore, since PHP 8.5. It is deprecated. As such, there is no point anymore to in passing such values to the first argument of array_key_exists(), and this is also deprecated.
Example¶
<?php
$array = [null => 1];
var_dump(array_key_exists(null, $array));
?>
Solutions¶
Use the coalesce operator
??to turn thenullinto another value, such as empty string.Replace the
nullvalue by the empty string.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See NullAsArrayOffset, NullWithArrayKeyExists.