Fix PHP 8.1 explode() deprecation notice

Created on 27 February 2023, over 1 year ago
Updated 8 June 2023, about 1 year ago

Problem/Motivation

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /var/www/html/web/modules/contrib/simple_sitemap/src/PathProcessor/PathProcessorSitemapVariantOut.php on line 19

public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    $args = explode('/', $path);
    if (count($args) === 4 && $args[3] === 'sitemap.xml') {
      $path = '/' . $args[2] . '/sitemap.xml';
    }

    return $path;
  }

}

Not compatible with php 8.1. $path in explode can't be null.

The module have to be patched, and replace the current code by, for example :

public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
    $args = explode('/', $path ?? '');
    if (count($args) === 4 && $args[3] === 'sitemap.xml') {
      $path = '/' . $args[2] . '/sitemap.xml';
    }

    return $path;
  }

}
πŸ“Œ Task
Status

Fixed

Version

4.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024