PHP 8.1 Deprecated function Notice when passing NULL to trim()
My Reports -> Recent Logs is inundated with Notices. Each row returned of a view I use for listing Events results in a Notice so it fills up pretty quickly.
Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in views_handler_field->render_text() (line 1195 of /views/handlers/views_handler_field.inc).
Steps to reproduce
Create a view for a content type and trim the whitespace of one or more fields. In my case, I have a field that I am using as a link. The link goes to the node ID and I am Trimming the Whitespace from the field.
Proposed resolution
I will attach a patch that casts the value as a string before it trims.
Remaining tasks
Please test and apply if it passes.
Cheers,
Andrew
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | Deprecated_function_trim_Passing_null_to_parameter_1_string-3313970-8.patch | 544 bytes | awasson |
| #2 | Deprecated_function_trim_Passing_null_to_parameter_1_string-3313970-2.patch | 514 bytes | awasson |
Comments
Comment #2
awasson commentedPatch is attached that casts the value as a string before it trims.
Comment #3
awasson commentedComment #4
awasson commentedComment #5
damienmckennaI think it would be worth extending this to cover more situations where trim() is executed on variables that might not be strings.
Comment #6
damienmckennaComment #7
awasson commented@DamienMcKenna, how about using is_null()? is_null() only tests if the variable is null so empty variables may still show up as an empty string but that should be ok.
Original code:
Test for NULL:
If this is acceptable, I'll create a patch.
Cheers,
Andrew
Comment #8
awasson commentedPatch attached.
Comment #9
avpadernoComment #10
damienmckennaCommitted. Thanks.