Skip to:
Content

bbPress.org

Opened 6 months ago

Last modified 2 months ago

#3585 new defect (bug)

Function utf8_encode() is deprecated since PHP 8.2

Reported by: philipjohn's profile 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

Change History (1)

#1 @probbpress
5 months ago

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():

// Deprecated way
$utf8 = utf8_encode("\xa5\xa7\xb5");

// New way using mb_convert_encoding
$utf8 = mb_convert_encoding("\xa5\xa7\xb5", 'UTF-8', 'ISO-8859-2');

And for utf8_decode():

// Deprecated way
$iso88592 = utf8_decode($utf8);

// New way using mb_convert_encoding
$iso88592 = mb_convert_encoding($utf8, 'ISO-8859-2', 'UTF-8');

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​​.

Last edited 5 months ago by johnjamesjacoby (previous) (diff)
Note: See TracTickets for help on using tickets.