Problem/Motivation
On PHP 8.5+, visiting the redirect settings page (/admin/config/search/redirect/settings) triggers a deprecation notice:
Deprecated function: Using null as an array offset is deprecated, use an empty string instead in redirect_status_code_options() (line 205 of redirect.module)
The function signature has a default of $code = NULL, and line 205 uses $codes[$code] directly in the null coalescing expression. When called without arguments (as RedirectSettingsForm::buildForm() does at line 70), $code is NULL, and PHP 8.5+ deprecates using null as an array key.
Steps to reproduce
- Use PHP 8.5 or later with deprecation notices visible.
- Go to Administration > Configuration > Search and metadata > URL redirects > Settings.
- Observe the deprecation notice.
Proposed resolution
Check for NULL explicitly before indexing:
- return $codes[$code] ?? $codes;
+ return $code !== NULL ? $codes[$code] : $codes;
Issue fork redirect-3579217
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
mably commentedComment #4
mably commentedComment #6
berdirThis has a slight behavior change but I think that's an improvement actually, a non-existing code would result in undefined array key changes, but that seems preferable over returning an array. Different return types is an antipattern. Nothing calls it with a code, but lets fix the deprecation notice. When converting to a method on a class, we should just remove the code argument I think.