Deprecated function: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\node_read_time\Calculate\ReadingTime->calculateReadingTime()

Created on 24 August 2022, almost 2 years ago
Updated 2 March 2023, over 1 year ago

Problem/Motivation

While testing on a client site, I realised that it's now possible for empty text fields to trigger the following: Deprecated function: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\node_read_time\Calculate\ReadingTime->calculateReadingTime() (line 186 of /var/www/html/docroot/modules/contrib/node_read_time/src/Calculate/ReadingTime.php)

Steps to reproduce

PHP 8.1, Drupal 9.4.5, node_read_time 8.x-1.6
A new / existing node is being saved with an optional text field, where node read time is implemented, empty.

Proposed resolution

strip_tags() doesn't like NULL anymore and that's finding its way here:
$words_count = count(preg_split('/\s+/', (strip_tags($this->words))));
A simple solution is to cast to string (though CS will say it's not necessary as $this->words is not supposed to be nullable).

πŸ› Bug report
Status

Fixed

Version

1.6

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom ORION web

Live updates comments and jobs are added and updated live.
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.69.0 2024