Fix PHP 8.1 explode() deprecation notice

Created on 27 February 2023, almost 2 years ago
Updated 8 June 2023, over 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

  • Issue created by @Nicoc
  • Status changed to Closed: won't fix almost 2 years ago
  • 🇩🇪Germany gbyte Berlin

    The 3.x version of this module is for Drupal <= 9.2 and PHP <= 8.0. As Drupal 9.2 is not supported anymore, I do not provide support for 3.x other than security updates. Please switch to 4.x.

  • 🇨🇭Switzerland megadesk3000

    I experience the exact same issue on the 4.x branch with D9.5 and PHP 8.1

  • 🇨🇭Switzerland megadesk3000

    Added a patch for 4.x

  • Status changed to Postponed: needs info almost 2 years ago
  • 🇩🇪Germany gbyte Berlin

    The path is supposed to be a string, always starting with an /; see \Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound.

    Can you debug when exactly it is NULL? I don't like adding type checks for a type that should not be there.

  • Status changed to Postponed over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Just ran into the same issue and can tell, that this always appears together with other issues. Core for example is also complainung.

    For me it happened on the frontpage, which (due to unknown reasons) had an empty URL alias!
    Se-saving the frontpage node and setting a proper URL alias fixed all these notices.

  • 🇨🇦Canada joseph.olstad

    With the Drupal 10 version of the wxt distro running PHP 8.1 if no url alias is specified on a node the above warnings spew out.

    Thankfully using patch 4 reduces the noise. I'm not sure what simple_sitemap is doing when node/add save/submit is triggered but my client wants the noise to be gone immediately so I'm using patch #4.

  • 🇵🇹Portugal introfini

    Also using #4. Thanks.

  • Status changed to Fixed over 1 year ago
  • 🇩🇪Germany gbyte Berlin

    This should not be a thing, but apparently it is. Commited into dev. Thanks!

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

Production build 0.71.5 2024