PHP 8.1 gives an error message for time calculation for ceil() function when read time is not available

Created on 4 January 2023, almost 2 years ago
Updated 5 June 2024, 7 months ago

Problem/Motivation

In some cases our node read time did not return a value. Debugging this showed that in the module where it retrieves the read time, we received a string value of 0.

This is then passed to PHP function ceil() which gives an error in PHP 8.1:
TypeError: ceil(): Argument #1 ($num) must be of type int|float, string given in function ceil() (line 152 in file /var/www/html/builds/2023-01-04.14-04-25.commit--afc366d/web/modules/contrib/read_time/read_time.module)

The error disappeared when the node was saved again and the actual read time was available but several content pages were broken because of this.

Proposed resolution

Make sure that the ceil() function int the module file is always receiving an int type of value.

I attached a small patch which makes sure that the value is always an int which seemed to fix the issue for us.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇫🇮Finland heikkiy Oulu

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.71.5 2024