Passing null to parameter #1 ($string) of type string is deprecated

Created on 24 April 2024, 8 months ago
Updated 29 April 2024, 8 months ago

Problem/Motivation

When I submit a webform, I received this error:

"\nAn AJAX HTTP error occurred.\nHTTP Result Code: 200\nDebugging information follows.\nPath: /webform/kian_webform/test?ajax_form=1\nStatusText: parsererror\nResponseText: \nDeprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/web/modules/contrib/webform_content_creator/src/Plugin/WebformContentCreator/FieldMapping/TextFieldMapping.php on line 85\nDeprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/web/modules/contrib/webform_content_creator/src/Plugin/WebformContentCreator/FieldMapping/TextFieldMapping.php on line 89

This is because $value passed into checkMaxFieldSizeExceeded() could be NULL.

    if ($max_length < strlen($value)) {
      \Drupal::logger(WebformContentCreatorInterface::WEBFORM_CONTENT_CREATOR)->notice($this->t('Problem: Field max length exceeded (truncated).'));
      return $max_length;
    }

Proposed resolution

In checkMaxFieldSizeExceeded(), return 0 if $value is empty.

🐛 Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

🇯🇵Japan hktang

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