Skip to content

Deprecation warning - use of null in str_replace - legacy/libraries/File_field.php (840) #4349

@jcogs-design

Description

@jcogs-design

Description of the problem
Issue reported by Chris Wong via Slack (@chunkitchris)
"I set up a local server with PHP 8.20 and did some initial work. Then, I exported the database and imported it to the production server, which is running PHP 8.2.12. I continued to work on the production site by entering data from my clients. After that, I exported the database and imported it back to my local server for further development. When I tried to access a channel with the Bloqs add-on, an error message was displayed.

Turns out this is caused by use of an untrapped call to $file->getAbsoluteURL() on line 840 of legacy/libraries/File_field.php. If the function call returns null, this is passed to str_replace() and it is this passing of null to the php function that causes the deprecation error.

How To Reproduce
As per description - in Chris' case it seems to have been triggered by something related to Bloqs add-on, but the cause of the warning is independent of that.

Error Messages


Deprecated
str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated
ee/legacy/libraries/File_field.php, line 840

Severity: E_DEPRECATED

Environment Details:

  • Version: 7.4.10
  • PHP Version 8.2.0
    Possible Solution
    Put in a check to ensure that the value returned by $file->getAbsoluteURL() is not null before calling the php str_replace function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions