Skip to content

[4.x] Deprecate the default_charset side effect of StringHelper - #82

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-default-charset-deprecation
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-default-charset-deprecation

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

When StringHelper.php is loaded, it runs @ini_set('default_charset', 'UTF-8') at file scope. That changes a process-wide setting, which affects the defaults of htmlspecialchars(), htmlentities() and html_entity_decode() and the charset of the Content-Type header. Whether it happens depends on whether some code has autoloaded the class yet. UTF-8 has been PHP's default since 5.6, so for most installations the call does nothing, and for the rest it is a surprise.

This PR deprecates the side effect so that it can be removed in 5.0. It cannot trigger a deprecation notice, because that would fire for every application on every request that loads the class. Instead:

  • the line gets a @deprecated 5.0 comment that explains the change;
  • docs/overview.md describes the side effect, says it is deprecated, and says what to do instead (set default_charset in php.ini or during bootstrap).

Nothing changes at runtime.

Testing Instructions

Docs and a code comment only. vendor/bin/phpunit is green and phpcs is clean.

Documentation Changes Required

docs/overview.md (still "TODO" on 4.x-dev) gets a section "Loading StringHelper changes default_charset". The removal, and its entry in docs/v4-to-v5-update.md, are a separate 5.x PR.

The owner's docs PR #72 has a section "A note on loading this package" that describes the side effect and advises setting default_charset after the class is loaded. Whichever of the two is merged second must merge the two texts and mention the deprecation there. Other open PRs (#73, #75, #77, #78, #79) also append sections to the docs/overview.md stub, so expect small conflicts.

🤖 Generated with Claude Code

Loading StringHelper.php runs ini_set('default_charset', 'UTF-8'),
which changes htmlspecialchars()/html_entity_decode() defaults and the
Content-Type charset process-wide, depending on whether some code has
loaded the class yet. UTF-8 has been PHP's default since 5.6.

A notice cannot be triggered at file load without firing for every
user, so mark the side effect as deprecated in the code and the docs;
it is removed in 5.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant