Opened 13 months ago
Last modified 10 months ago
#3585 new defect (bug)
Function utf8_encode() is deprecated since PHP 8.2
Reported by: | philipjohn | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 2.6.9 |
Component: | Tools - Warnings/Notices | Keywords: | |
Cc: |
Description
PHPCS running on PHP v8.2 gives us the following warning:
Function utf8_encode() is deprecated since PHP 8.2; Use mb_convert_encoding(), UConverter::transcode() or iconv instead (PHPCompatibility.FunctionUse.RemovedFunctions.utf8_encodeDeprecated)
It affects two places:
- includes/replies/template.php:1103
- includes/topics/template.php:1336
Note: See
TracTickets for help on using
tickets.
The deprecation of utf8_encode() and utf8_decode() in PHP 8.2 means that these functions are no longer recommended for use and will likely be removed in future PHP versions. These functions were originally used for converting strings from ISO-8859-1 to UTF-8 encoding and vice versa. However, they have been deprecated due to issues such as misleading function names, lack of error messages, and no support for detecting or converting other character encodings like UTF-16 to UTF-8.
To address this deprecation in BBPress or any PHP script, you should replace utf8_encode() and utf8_decode() with the mb_convert_encoding() function from the mbstring extension, which is more versatile and supports a wide range of character encodings. Alternatively, the iconv or intl extensions can also be used for character encoding conversion.
Here is an example of how you can replace utf8_encode() with mb_convert_encoding():
And for utf8_decode():
For the specific files you mentioned, you will need to locate the lines where utf8_encode() and utf8_decode() are used and replace them with the appropriate mb_convert_encoding() calls, ensuring you specify the correct source and target encodings.