[php-src] Issue #13815: mb_trim() inaccurate $characters default value
| From: | ranvis | Date: | Tue, 26 Mar 2024 22:33:15 +0000 |
| Subject: | [php-src] Issue #13815: mb_trim() inaccurate $characters default value | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246657@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13815
Author: ranvis
### Description
```php
function mb_trim(string $string, string $characters = "
\f\n\r\t\v\x00\u{00A0}...\u{180E}", ?string $encoding = null): string {}
```
The default values for the parameter
$characters of the new mb_trim functions are not
accurate.
When the very same value as the default is implied to $characters like the code below,
mb_trim() does not necessarily work the same way, because $characters also
depends on $encoding.
The parameter should be typed as ?string $characters = null instead.
```php
<?php
$strUtf8 = "\u{3042}\u{3000}"; // U+3000: fullwidth space
var_dump(mb_strlen(mb_trim($strUtf8))); // 1
var_dump(mb_strlen(mb_trim($strUtf8, encoding: 'UTF-8'))); // 1
mb_internal_encoding('Shift_JIS');
$strSjis = mb_convert_encoding($strUtf8, 'Shift_JIS', 'UTF-8');
var_dump(mb_strlen(mb_trim($strSjis))); // 1
var_dump(mb_strlen(mb_trim($strSjis, encoding: 'Shift_JIS'))); // 2
```
### PHP Version
PHP dev-master
### Operating System
_No response_