[D7 PHP 8.1] mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in drupal_strlen()

Created on 24 October 2023, 8 months ago
Updated 16 November 2023, 8 months ago

Problem/Motivation

We are experiencing multiple deprecation warnings on PHP 8.1 in the drupal_strlen() function:

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

Steps to reproduce

Save a select_or_other β†’ field in the field settings UI. This field's main $elements array when inside _form_validate() has 2 sub elements that have the #value as not null, but in that function it runs
elseif (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) { without ensuring a string value.

Proposed resolution

Cast the input as a string.

πŸ› Bug report
Status

Closed: duplicate

Version

7.0 ⚰️

Component
BaseΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡¨πŸ‡¦Canada joelpittet Vancouver

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

Production build 0.69.0 2024