Deprecate NULL values in Html::escape(), ::decodeEntities(), and FormattableMarkup::placeholderFormat() to make it easier to upgrade to PHP 8

Created on 22 December 2021, over 3 years ago
Updated 15 May 2025, 22 days ago

Problem/Motivation

PHP 8.1 has deprecating passing NULLs to many string manipulating functions. This can cause contrib tests to fail with:

htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated.

This is due to FormattableMarkup replacements being null - those go straight as nulls down to Html::escape() and hence to htmlspecialchars(), where PHP 8.1 complains.

Proposed resolution

The PHP deprecation can be really hard to debug because you don't get a stack trace. Therefore, this issue adds a deprecation to FormattableMarkup that tells you which string and argument key is causing the problem.

Remaining tasks

None

User interface changes

None

API changes

Html::escape and Html::decodeEntities are typehinted to return string. This is okay because these are static functions.

Data model changes

None

Release notes snippet

Passing a NULL value as a placeholder value to translatable markup or formattable markup is deprecated and will cause an exception in Drupal 11.

🐛 Bug report
Status

Fixed

Version

9.5

Component

base system

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States john.oltman

    A custom entity type without a label will trigger the error mentioned by @ghost-of-drupal-past when using a DraggableListBuilder and when saving the entity using EntityForm. I'll open a separate issue, but the solution might be a rollback of this change.

Production build 0.71.5 2024