Bug #77907 [Asn]: mb-functions do not respect default_encoding
| From: | nikic@php.net | Date: | Tue, 16 Apr 2019 14:40:20 +0000 |
| Subject: | Bug #77907 [Asn]: mb-functions do not respect default_encoding | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220489@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77907&edit=1
ID: 77907
Updated by: nikic@php.net
Reported by: n dot scheer at binserv dot de
Summary: mb-functions do not respect default_encoding
Status: Assigned
Type: Bug
Package: *Unicode Issues
Operating System: CentOS 7.6.1810
PHP Version: 7.2.17
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
https://github.com/php/php-src/pull/4035
Probably 7.4 only, this is a non-trivial change.
Previous Comments:
------------------------------------------------------------------------
[2019-04-16 14:13:20] nikic@php.net
Working on this right now...
------------------------------------------------------------------------
[2019-04-16 14:06:54] n dot scheer at binserv dot de
Description:
------------
The documentation states (c.f. https://www.php.net/manual/en/ini.core.php#ini.default-charset):
"In PHP 5.6 onwards, "UTF-8" is the default value and [...] The value of
default_charset
will also be used to set the default character set for [...] and for mbstring functions
if the mbstring.http_input mbstring.http_output mbstring.internal_encoding
configuration option is unset."
As such, I'd expect to be able to set default_charset to iso-8859-1 and mbstring to pick that
same setting for its internal encoding (if the mentioned directives are unset, that is).
In the test script below the output of mb_strlen should be "2" in both cases, as
iso-8859-1 is a single byte encoding. This is not the case, instead it seems that the two bytes are
recognized as the utf-8 character "ö".
If mb_internal_encoding is set explicitly, the mb-functions work as expected.
But it should in fact not be needed to use mb_internal_encoding() nor the ini setting for it,
because default_charset should be used as default.
Test script:
---------------
<?php
ini_set('default_charset', 'iso-8859-1');
var_dump(ini_get("mbstring.internal_encoding"));
var_dump(ini_get("mbstring.http_input"));
var_dump(ini_get("mbstring.http_output"));
var_dump(mb_internal_encoding());
var_dump(mb_strlen( "\xc3\xb6" ));
var_dump(mb_strlen( "\xc3\xb6", '8bit' ));
mb_internal_encoding('iso-8859-1');
var_dump(mb_internal_encoding());
var_dump(mb_strlen( "\xc3\xb6" ));
var_dump(mb_strlen( "\xc3\xb6", '8bit' ));
Expected result:
----------------
string(0) ""
string(0) ""
string(0) ""
string(5) "UTF-8"
int(1)
int(2)
string(10) "ISO-8859-1"
int(2)
int(2)
Actual result:
--------------
string(0) ""
string(0) ""
string(0) ""
string(5) "UTF-8"
int(2)
int(2)
string(10) "ISO-8859-1"
int(2)
int(2)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77907&edit=1