PHP 8.1: Passing null to parameter #1 ($string) of type string is deprecatedPassing null to parameter #1 ($string) of type string is deprecated

Created on 11 January 2023, over 1 year ago
Updated 12 February 2024, 4 months ago

Problem/Motivation

When saving an existing media item I get the following warnings, due to the hook_file_validate() for the module not properly checking if $file->destination is set or not.

Deprecated function: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\File\FileSystem->basename() (line 166 of core/lib/Drupal/Core/File/FileSystem.php).
Drupal\Core\File\FileSystem->basename(NULL) (Line: 23)
transliterate_filenames_file_validate(Object)
Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme() (line 256 of core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php).
Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme(NULL) (Line: 146)
Drupal\Core\File\FileSystem->dirname(NULL) (Line: 25)
transliterate_filenames_file_validate(Object)
Deprecated function: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in Drupal\Core\File\FileSystem->dirname() (line 152 of core/lib/Drupal/Core/File/FileSystem.php).
Drupal\Core\File\FileSystem->dirname(NULL) (Line: 25)
transliterate_filenames_file_validate(Object)
call_user_func_array(Object, Array) (Line: 426)

Steps to reproduce

Edit an existing media element while using PHP 8.1, and save it without making any changes.

Proposed resolution

The simplest way is to check if this value is set, and if not simply do nothing.

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡΅πŸ‡ΉPortugal jcnventura

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States KurtTrowbridge

    I know this module is obsolete now, and we'll be getting rid of it on the site on which I tested this once it's upgraded to Drupal 10, but for any other fellow stragglers on Drupal 9, the patch in #2 solves the issue.

Production build 0.69.0 2024