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.

Comments

Volha_Si created an issue. See original summary.

volha_si’s picture

StatusFileSize
new684 bytes
liam morland’s picture

Issue tags: -php8.1 +PHP 8.1
volha_si’s picture

Status: Active » Needs review
liam morland’s picture

Version: 7.x-3.13 » 7.x-3.x-dev
Status: Needs review » Needs work
Issue tags: +Needs reroll
akashkumar07’s picture

StatusFileSize
new692 bytes

Adding a reroll of #2.

akashkumar07’s picture

Status: Needs work » Needs review
damienmckenna’s picture

Status: Needs review » Needs work

Thank you for reporting the problem and for providing a patch.

Views needs to retain compatibility with PHP 5, so this won't work as-is.

damienmckenna’s picture

Issue tags: -Needs reroll

I think this needs further work as none of the logic in the "else" section of that code should run if the value is NULL.

joseph.olstad’s picture

StatusFileSize
new718 bytes

Hopefully PHP 5 can deal with this.

joseph.olstad’s picture

StatusFileSize
new727 bytes

oops, try this.

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community
damienmckenna’s picture

Status: Reviewed & tested by the community » Needs review
Parent issue: » #3347650: Plan for Views 7.x-3.30
StatusFileSize
new739 bytes

isset() and !is_null() are a bit redundant, and neither confirm that the value is numerical.

How about this?

tibezh’s picture

Status: Needs review » Reviewed & tested by the community

Seems looks good.

joseph.olstad’s picture

Looks great, thanks @DamienMcKenna

damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Excellent, thanks for the quick reviews.

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.