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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | imce-php_8_2_utf8_encode_is-3410945-3-D7.patch | 6.11 KB | hargobind |
Issue fork imce-3410945
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
Comment #2
hargobindAttached patch uses the proposed resolution.
Comment #3
hargobindFix for accidental overwriting of string in last patch.
Comment #4
hargobindComment #6
ufku commentedDuplicate of #3432074: PHP8.2: Deprecated utf8_encode()