PHP 8.2: utf8_encode is deprecated

Created on 27 December 2023, 11 months ago
Updated 27 February 2024, 9 months ago

Problem/Motivation

PHP 8.2 notes that utf8_encode() and utf8_decode() are deprecated because they can introduce obscure bugs. More info here.

Steps to reproduce

Use of the functions are found in branch 7.x-2.x and below. 8.x and 3.x don't use these functions.

Proposed resolution

The functions convert strings between ISO-8859-1 (Also known as "Latin 1") and UTF-8 encodings. These functions do not attempt to detect the actual character encoding in a given text, and always convert character encodings between ISO-8859-1 and UTF-8, even if the source text is not encoded in ISO-8859-1.

So instead of assuming ISO-8859-1, it seems like the best approach is to first detect the encoding then to convert it.

Example:
mb_convert_encoding($item, "UTF-8", mb_detect_encoding($item));

Patch coming in a followup comment.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States hargobind Austin, Texas

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

Comments & Activities

Production build 0.71.5 2024