Deprecated function: strtr(): Passing null to parameter #1 ($string) of type string is deprecated in paragraphs_theme_suggestions_paragraph()

Created on 16 September 2022, about 2 years ago
Updated 6 August 2024, 4 months ago

"Deprecated function: strtr(): Passing null to parameter #1 ($string) of type string is deprecated in paragraphs_theme_suggestions_paragraph() (line 107 of modules/contrib/paragraphs/paragraphs.module)."

After the upgrade to PHP 8.1, apparently some functions no longer accept working with NULL parameters, which happened in this file specifically in the strtr() function.

I propose a simple null coalescence validation (??) to solve this problem.

file: modules/contrib/paragraphs/paragraphs.module

Before patch:

function paragraphs_theme_suggestions_paragraph(array $variables) {
...
  $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
 ...

After patch:

function paragraphs_theme_suggestions_paragraph(array $variables) {
...
  $sanitized_view_mode = strtr($variables['elements']['#view_mode'] ?? '', '.', '_');
...
🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇧🇷Brazil ctrevisa

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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024