Fix 8.1 compatibility issues: abs() and ceil() cannot handle null

Created on 24 July 2023, over 1 year ago
Updated 4 January 2024, 11 months ago

Errors on php8.1 in views_handler_field_numeric->render()

I faced the next warnings:
Deprecated function: abs(): Passing null to parameter #1 ($num) of type int|float is deprecated in views_handler_field_numeric->render() (line 114 of views/handlers/views_handler_field_numeric.inc).
Deprecated function: ceil(): Passing null to parameter #1 ($num) of type int|float is deprecated in views_handler_field_numeric->render() (line 115 of views/handlers/views_handler_field_numeric.inc).

There errors appeared when the taxonomy term without the parent was displayed by the view. The variable $values['taxonomy_term_data_taxonomy_term_hierarchy_tid'] is set as NULL in this case and cannot be handled via abs() and ceil() without warnings.

Proposed resolution

In case the $value is not set - replace it with 0 (see patch attached). It'll fix the warnings and leave the function output unchanged.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Miscellaneous

Created by

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