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

  1. Use PHP 8.5 or later with deprecation notices visible.
  2. Go to Administration > Configuration > Search and metadata > URL redirects > Settings.
  3. 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

Command icon 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

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review
mably’s picture

Issue summary: View changes

  • berdir committed d621286a on 8.x-1.x authored by mably
    feat: #3579217 Deprecation notice: null used as array offset in...
berdir’s picture

Status: Needs review » Fixed

This 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.