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.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | views-n3376468-13.patch | 739 bytes | damienmckenna |
Comments
Comment #2
volha_si commentedComment #3
liam morlandComment #4
volha_si commentedComment #5
liam morlandComment #6
akashkumar07 commentedAdding a reroll of #2.
Comment #7
akashkumar07 commentedComment #8
damienmckennaThank 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.
Comment #9
damienmckennaI think this needs further work as none of the logic in the "else" section of that code should run if the value is NULL.
Comment #10
joseph.olstadHopefully PHP 5 can deal with this.
Comment #11
joseph.olstadoops, try this.
Comment #12
joseph.olstadComment #13
damienmckennaisset() and !is_null() are a bit redundant, and neither confirm that the value is numerical.
How about this?
Comment #14
tibezh commentedSeems looks good.
Comment #15
joseph.olstadLooks great, thanks @DamienMcKenna
Comment #17
damienmckennaExcellent, thanks for the quick reviews.
Committed.