PHP 8.1 deprecation error in hook_url_outbound_alter()

Created on 30 January 2023, almost 2 years ago
Updated 23 June 2024, 6 months ago

Problem/Motivation

PHP 8.1 introduces a deprecation for passing null to non-nullable parameters of built-in functions.

As a result, the use of explode() in commerce_checkout_paths_url_outbound_alter results in the following error:

PHP 8.1 Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated

Steps to reproduce

This error appears anytime that the module is enabled.

This is because template_preprocess_page() in includes/theme.inc has the line $variables['front_page'] = url();. Calling url() with no parameters leads to hook_url_outbound_alter() being passed NULL values for $path and $original_path.

Proposed resolution

Check if $original_path is a string before calling explode().

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States hargobind Austin, Texas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024