Problem/Motivation
We are experiencing multiple deprecation warnings on PHP 8.1 in the text_summary() function:
Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in text_summary() (line 358 of /modules/field/modules/text/text.module).
Deprecated function: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in drupal_strlen() (line 482 of /includes/unicode.inc).
The first one is directly in text_summary()
and the second one is in drupal_strlen()
function which is called by text_summary()
.
The problem is not the Drupal core itself, but some modules seems to be calling text_summary() with null, which results in this warning. I can point out at Metatag module trying to generate node tokens, but it seems like this is not the only one module causing this. This will happen when there is a node with a text_with_summary
field type and this field has a null value. Some modules are directly using this null value (like Metatag module) and it will end up with this deprecation warnings.
A im posting this as a Drupal core issue, because in some other issues we went the way of sanitizing it on the Drupal core side, as multiple modules can cause this. See the recent check_plain()
fix: #3254699: [D7 PHP 8.1] check_plain(): Passing null to parameter #1 check_plain() includes/bootstrap.inc, line 1907