Html::escape() and FormattableMarkup::placeholderEscape() needs a type declaration to prevent it from passing invalid values to htmlspecialchars(). This can only be done in Drupal 10 since it requires union types which are only support in PHP 8.1.
Original report:
Problem/Motivation
I had contrib functional tests failing 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.
This is not happening in core so no core tests were complaining.