Deprecated function: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\admin_feedback\Controller\AdminFeedbackController->exportDbFeedback()

Created on 2 April 2024, 7 months ago
Updated 4 July 2024, 4 months ago

Problem/Motivation

Steps to reproduce

When exporting feedback, for every feedback entry without a message, a deprecation warning, as follows is logged:

Deprecated function: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\admin_feedback\Controller\AdminFeedbackController->exportDbFeedback() (line 296 of /opt/drupal/web/modules/contrib/admin_feedback/src/Controller/AdminFeedbackController.php)

Proposed resolution

The issue can be easily mitigated by using a null coalescing operator to provide a blank string. Implementing this as suggested would change Line 296 from:

      $message_formatted = trim(preg_replace('/\s+/', '  ', $row->feedback_message));

to:

      $message_formatted = trim(preg_replace('/\s+/', '  ', $row->feedback_message ?? ''));

Remaining tasks

Create a merge request to ensure that null is not passed to the third argument of the preg_replace function.

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024