Skip to content

PHP 8.2 deprecated utf8_decode #38922

@nikosdion

Description

@nikosdion

Steps to reproduce the issue

  • Install Joomla 4.2 on PHP 8.2 (PHP 8.2 is still in development)

Expected result

No deprecated notices :trollface:

Actual result

(Among other deprecated notices)

Deprecated: Function utf8_decode() is deprecated in .../boot4/libraries/vendor/joomla/uri/src/UriHelper.php on line 36

System information (as much as possible)

PHP 8.2 is the only relevant thing

Additional comments

utf8_encode and utf8_decode are deprecated in PHP 8.2.

You can replace the calls to the deprecated function with calls to the following method:

public static function utf8_decode($s)
	{
		if (version_compare(PHP_VERSION, '8.1.999', 'le'))
		{
			return utf8_decode($s);
		}

		if (function_exists('mb_convert_encoding'))
		{
			return mb_convert_encoding($s, 'ISO-8859-1', 'UTF-8');
		}

		if (class_exists('UConverter'))
		{
			return UConverter::transcode($s, 'ISO-8859-1', 'UTF8');
		}

		if (function_exists('iconv'))
		{
			return iconv('UTF-8', 'ISO-8859-1', $s);
		}

		/**
		 * Fallback to the pure PHP implementation from Symfony Polyfill for PHP 7.2
		 *
		 * @see https://github.com/symfony/polyfill-php72/blob/v1.26.0/Php72.php
		 */
		$s = (string) $s;
		$len = \strlen($s);

		for ($i = 0, $j = 0; $i < $len; ++$i, ++$j) {
			switch ($s[$i] & "\xF0") {
				case "\xC0":
				case "\xD0":
					$c = (\ord($s[$i] & "\x1F") << 6) | \ord($s[++$i] & "\x3F");
					$s[$j] = $c < 256 ? \chr($c) : '?';
					break;

				case "\xF0":
					++$i;
				// no break

				case "\xE0":
					$s[$j] = '?';
					$i += 2;
					break;

				default:
					$s[$j] = $s[$i];
			}
		}

		return substr($s, 0, $j);
	}

Tagging @nibra @Hackwar as this is a Joomla Framework issue, @HLeithner @laoneo because this touches architecture and may be happening in other places in the code I have not come across yet.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions