Problem/Motivation

We are experiencing multiple deprecation warnings on PHP 8.1 in the decode_entities() function:

Deprecated function: html_entity_decode(): Passing null to parameter #1 ($string) of type string is deprecated in decode_entities() (line 463 of includes/unicode.inc).

I'm posting this as prior art #3270881: [D7 PHP 8.1] strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in text_summary(). I've been posting issues on the originating modules to solve this but it's coming from the same source in core.

Steps to reproduce

Proposed resolution

Cast the input as a string.

Issue fork drupal-3396440

Command icon Show commands

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

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review

poker10 made their first commit to this issue’s fork.

tibezh’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.
The patch covers really important things to support PHP 8.1 on D7.

poker10’s picture

I think this looks good. This code

var_dump(html_entity_decode(NULL, ENT_QUOTES, 'UTF-8'));

in PHP 8.3, 8.2, 8.1 results in:

Deprecated: html_entity_decode(): Passing null to parameter #1 ($string) of type string is deprecated
string(0) ""

and in PHP 7.4, 7.3 and lower in:

string(0) ""

So by casting to string we will keep the same behavior of this function - an empty string will be returned without a deprecation message.

I have added a NULL value to the existing tests. Seems like all pipelines are green (https://git.drupalcode.org/project/drupal/-/pipelines/59079), so adding a tag for the final review. Here is a test-only test which failed as expected: https://git.drupalcode.org/project/drupal/-/jobs/434910. Thanks.

fabianx’s picture

RTBC

  • mcdruid committed 68ca415f on 7.x
    Issue #3396440 by poker10, joelpittet, tibezh, Fabianx: [D7 PHP 8.1]...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Thanks everybody!

Status: Fixed » Closed (fixed)

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