Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Tests/DefaultCharsetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* @copyright Copyright (C) 2026 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\String\Tests;

use Joomla\String\StringHelper;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

/**
* Test that loading StringHelper has no side effects on the PHP configuration.
*/
class DefaultCharsetTest extends TestCase
{
/**
* @testdox Loading StringHelper does not change the default_charset setting
*/
#[RunInSeparateProcess]
public function testLoadingStringHelperKeepsDefaultCharset()
{
$this->assertFalse(class_exists(StringHelper::class, false), 'StringHelper must not be loaded yet.');

ini_set('default_charset', 'ISO-8859-1');

$this->assertTrue(class_exists(StringHelper::class));
$this->assertSame('ISO-8859-1', ini_get('default_charset'));
}
}
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* [Overview](overview.md)
* [Updating from v4 to v5](v4-to-v5-update.md)
11 changes: 11 additions & 0 deletions docs/v4-to-v5-update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Updating from v4 to v5

The following changes were made to the String package between version 4 and version 5.

### Loading `StringHelper` no longer changes `default_charset`

In 4.x, loading `StringHelper.php` ran `@ini_set('default_charset', 'UTF-8')`, which changed a
process-wide PHP setting as a side effect. This has been removed. `UTF-8` has been PHP's default for
`default_charset` since PHP 5.6. If your `php.ini` sets a different value and your application relies
on `UTF-8`, for example for `htmlspecialchars()` or the `Content-Type` header, set it yourself in
`php.ini` or with `ini_set('default_charset', 'UTF-8')` during bootstrap.
3 changes: 0 additions & 3 deletions src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

namespace Joomla\String;

// PHP mbstring and iconv local configuration
@ini_set('default_charset', 'UTF-8');

/**
* String handling class for UTF-8 data wrapping the phputf8 library. All functions assume the validity of UTF-8 strings.
*
Expand Down Expand Up @@ -330,7 +327,7 @@
*/
public static function str_pad($input, $length, $padStr = ' ', $type = STR_PAD_RIGHT)
{
return mb_str_pad($input, $length, $padStr, $type);

Check failure on line 330 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_str_pad not found.
}

/**
Expand Down Expand Up @@ -605,10 +602,10 @@
}

if ($charlist === false) {
return mb_ltrim($str);

Check failure on line 605 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_ltrim not found.
}

return mb_ltrim($str, $charlist);

Check failure on line 608 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_ltrim not found.
}

/**
Expand All @@ -632,10 +629,10 @@
}

if ($charlist === false) {
return mb_rtrim($str);

Check failure on line 632 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_rtrim not found.
}

return mb_rtrim($str, $charlist);

Check failure on line 635 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_rtrim not found.
}

/**
Expand All @@ -659,10 +656,10 @@
}

if ($charlist === false) {
return mb_trim($str);

Check failure on line 659 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_trim not found.
}

return mb_trim($str, $charlist);

Check failure on line 662 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_trim not found.
}

/**
Expand All @@ -684,14 +681,14 @@
public static function ucfirst($str, $delimiter = null, $newDelimiter = null)
{
if ($delimiter === null) {
return mb_ucfirst($str);

Check failure on line 684 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Function mb_ucfirst not found.
}

if ($newDelimiter === null) {
$newDelimiter = $delimiter;
}

return implode($newDelimiter, array_map('mb_ucfirst', explode($delimiter, $str)));

Check failure on line 691 in src/StringHelper.php

View workflow job for this annotation

GitHub Actions / framework-ci / Run PHPstan

Parameter #1 $callback of function array_map expects (callable(string): mixed)|null, 'mb_ucfirst' given.
}

/**
Expand Down
Loading