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
11 changes: 11 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# String package

TODO

## Loading `StringHelper` changes `default_charset`

When `StringHelper.php` is loaded, it runs `@ini_set('default_charset', 'UTF-8')` at file scope. This
changes a process-wide setting, which is the default character set of `htmlspecialchars()`,
`htmlentities()`, `html_entity_decode()` and the `Content-Type` header that PHP sends. Whether it
happens depends on whether some code has loaded the class yet.

This side effect is deprecated and will be removed in 5.0. `UTF-8` has been PHP's default for
`default_charset` since PHP 5.6. An application that needs `UTF-8` and runs with a different
`php.ini` value should set `default_charset` itself, in `php.ini` or with `ini_set()` during bootstrap.
1 change: 1 addition & 0 deletions src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Joomla\String;

// PHP mbstring and iconv local configuration
// @deprecated 5.0 Loading this file will no longer change the process-wide default_charset setting. UTF-8 is PHP's default.
@ini_set('default_charset', 'UTF-8');

/**
Expand Down Expand Up @@ -330,7 +331,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 334 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 +606,10 @@
}

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

Check failure on line 609 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 612 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 +633,10 @@
}

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

Check failure on line 636 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 639 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 +660,10 @@
}

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

Check failure on line 663 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 666 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 +685,14 @@
public static function ucfirst($str, $delimiter = null, $newDelimiter = null)
{
if ($delimiter === null) {
return mb_ucfirst($str);

Check failure on line 688 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 695 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