php-src icon indicating copy to clipboard operation
php-src copied to clipboard

mb_convert_encoding returns empty string since PHP 8.1.0

Open RV7PR opened this issue 4 years ago • 2 comments

Description

The following code:

<?php
$str = 'Test';

# Make sure string is in UTF-8 and strip invalid UTF-8 characters
$str = mb_convert_encoding($str, 'UTF-8', mb_list_encodings());

print_r($str);

Resulted in this output:


But I expected this output instead:

Test

This code is from a gist we use https://gist.github.com/sgmurphy/3098978

PHP Version

PHP 8.1.0

Operating System

CentOS 7

RV7PR avatar Jan 06 '22 20:01 RV7PR

I can confirm this for PHP 8.1.1, but it looks like the issue has been fixed with f07c1935839bf87e9d5a26a82a0ed8747c4f178f, which is contained in PHP 8.1.2RC1. Could you please check with that pre-release?

cmb69 avatar Jan 07 '22 00:01 cmb69

[root@RO ~]# php81 -v
PHP 8.1.2RC1 (cli) (built: Jan  4 2022 18:35:06) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.2RC1, Copyright (c) Zend Technologies
[root@RO ~]# php81 -r 'print_r(mb_convert_encoding("Test", "UTF-8", mb_list_encodings()));'
Test

I can confirm that it's fixed🚀

RV7PR avatar Jan 07 '22 14:01 RV7PR