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

Created on 14 January 2023, almost 2 years ago
Updated 14 September 2023, over 1 year ago

Problem/Motivation

When using PHP 8.1, if the image has no title ($image['title'] is NULL) the following error is displayed:

Deprecated function: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in drupal_strlen() (line 485 of /var/www/html/includes/unicode.inc).

This is because theme_cs_adaptive_image_formatter has this code:

  if (drupal_strlen($item['title']) > 0) {
    $image['title'] = $item['title'];
  }

That passes NULL to drupal_strlen(), which leads to the following:

    return mb_strlen($text);

That's where the error is thrown.

Proposed resolution

Don't call drupal_strlen() if $image['title'] is empty.

Remaining tasks

Provide a patch.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

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

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