Closed (fixed)
Project:
Feeds
Version:
8.x-3.0-beta2
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
1 Mar 2022 at 21:57 UTC
Updated:
26 Aug 2022 at 13:33 UTC
Jump to comment: Most recent
When using PHP 8.1 - Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\feeds\Plugin\Field\FieldType\FeedsItem->preSave() (line 132 of /modules/contrib/feeds/src/Plugin/Field/FieldType/FeedsItem.php)
Patch preSave() by null-coalescing the trim() argument to an empty string.
Convert to patch or merge request.
None.
None.
None.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #5
megachrizI think using
is_string($this->guid)would fix the issue as well. See branch "3267244-pass-null-to-trim-deprecated".Comment #6
tmaiochi commentedI'll review this!
Comment #7
tmaiochi commentedThe code prevent the message error about trim function, and the error wasn't showed any more as far as I can test!
Comment #9
megachrizThanks for testing! Changes from 3267244-pass-null-to-trim-deprecated are merged.
Comment #11
bwoods commentedSince upgrading to PHP 8.1, I've noticed a fair number of these pesky trim functions hiding out in the FieldTargetBase classes. At least in my situation, it seems that I'm hitting these because I have null values for some fields being passed, so I can run an isset check. But I guess I'm questioning whether there's a better/earlier way to do it if others are not seeing the same depreciation. Probably the most basic example is the Integer class. If we need a patch to fix all of these, I could start another ticket. But if I shouldn't actually have null values get this far, maybe I should change something in my API calls.
Comment #12
drupgirl commentedSorry to reopen. The patch doesn't apply cleanly to 3.0-beta2.
Comment #13
megachriz@drupgirl
That is because the patch is already committed.
@bwoods
It is possible that in files other than FeedsItem.php a similar issue exists. One new issue is opened importing date values: #3306211: Deprecated function: trim(): Passing null is deprecated as of PHP 8. To fix/catch these we need to have your particular case covered by an automated test. Tests are useful to prevent a bug from reappearing when making changes to the Feeds code base.
I think Feeds should be able to handle incoming null values well, so you should not have to change your API.
Whenever you encounter such an error, provide the feed type configuration file + the source file you were trying to import. Then I (or someone else) can write a test for that particular configuration and source data and have the bug covered.