diff --git a/Tests/DefaultCharsetTest.php b/Tests/DefaultCharsetTest.php new file mode 100644 index 00000000..a1d52699 --- /dev/null +++ b/Tests/DefaultCharsetTest.php @@ -0,0 +1,32 @@ +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')); + } +} diff --git a/docs/index.md b/docs/index.md index c87f1b49..b0b9f85c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1 +1,2 @@ * [Overview](overview.md) +* [Updating from v4 to v5](v4-to-v5-update.md) diff --git a/docs/v4-to-v5-update.md b/docs/v4-to-v5-update.md new file mode 100644 index 00000000..4af923aa --- /dev/null +++ b/docs/v4-to-v5-update.md @@ -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. diff --git a/src/StringHelper.php b/src/StringHelper.php index 98f73e7d..3e80b11f 100644 --- a/src/StringHelper.php +++ b/src/StringHelper.php @@ -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. *