Bug #77907 [NEW]: mb-functions do not respect default_encoding
| From: | n dot scheer at binserv dot de | Date: | Tue, 16 Apr 2019 14:06:54 +0000 |
| Subject: | Bug #77907 [NEW]: mb-functions do not respect default_encoding | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-220486@lists.php.net to get a copy of this message | ||
From: n dot scheer at binserv dot de
Operating system: CentOS 7.6.1810
PHP version: 7.2.17
Package: *Unicode Issues
Bug Type: Bug
Bug description:mb-functions do not respect default_encoding
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 bug report at https://bugs.php.net/bug.php?id=77907&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77907&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77907&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77907&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77907&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77907&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77907&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77907&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77907&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77907&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77907&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77907&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77907&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77907&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77907&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77907&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77907&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77907&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77907&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77907&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77907&r=mysqlcfg