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

CommentFileSizeAuthor
#2 cs_adaptive_image-n3333578-2.patch467 bytesdamienmckenna

Comments

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new467 bytes

This just checks that the variable exists and is not empty() before calling drupal_strlen().

alexh’s picture

Just had the same issue when upgrading to PHP 8.1 and the patch solved the issue. Thanks!

vuil’s picture

Status: Needs review » Reviewed & tested by the community

  • vuil committed 302506b3 on 7.x-1.x
    Issue #3333578 by damienmckenna, alexh, vuil: Deprecated function:...
vuil’s picture

Status: Reviewed & tested by the community » Fixed

Committed. I close the issue as resolved (Fixed).

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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