Update call to htmlspecialchars for PHP 8.1

Created on 6 September 2023, 10 months ago

Problem/Motivation

PHP 8.0 will be end-of-life in November. Codesniffer found one issue in the module for PHP 8.1.

Steps to reproduce

Run a codesniffer with PHP 8.1 compatibility rules on the Tablefield module.
Note this error is returned:

tablefield/tablefield.module
----------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 3 WARNINGS AFFECTING 5 LINES
----------------------------------------------------------------------------------------
 1004 | ERROR   | The default value of the $flags parameter for htmlspecialchars() was changed from
      |         | ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 in PHP 8.1. For
      |         | cross-version compatibility, the $flags parameter should be explicitly set.
 1848 | WARNING | INI directive 'auto_detect_line_endings' is deprecated since PHP 8.1
 1849 | WARNING | INI directive 'auto_detect_line_endings' is deprecated since PHP 8.1
 1879 | WARNING | INI directive 'auto_detect_line_endings' is deprecated since PHP 8.1
 2577 | ERROR   | The default value of the $flags parameter for htmlspecialchars() was changed from
      |         | ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 in PHP 8.1. For
      |         | cross-version compatibility, the $flags parameter should be explicitly set.
---------------------------------------------------------------------------------------- 

Proposed resolution

Update the function call to htmlspecialchars() to explicitly set the flags parameter to ENT_COMPAT, which should produce the same results across all supported PHP versions.

There are also deprecation warnings about auto_detect_line_endings. This is deprecated in PHP 8.1 but will not be removed until PHP 9.0, which won't be required until after Drupal 7 EOL.

Remaining tasks

Patch and test.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ“Œ Task
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cboyden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024