Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
When
StringHelper.phpis loaded, it runs@ini_set('default_charset', 'UTF-8')at file scope. That changes a process-wide setting, which affects the defaults ofhtmlspecialchars(),htmlentities()andhtml_entity_decode()and the charset of theContent-Typeheader. Whether it happens depends on whether some code has autoloaded the class yet.UTF-8has 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:
@deprecated 5.0comment that explains the change;docs/overview.mddescribes the side effect, says it is deprecated, and says what to do instead (setdefault_charsetinphp.inior during bootstrap).Nothing changes at runtime.
Testing Instructions
Docs and a code comment only.
vendor/bin/phpunitis green and phpcs is clean.Documentation Changes Required
docs/overview.md(still "TODO" on4.x-dev) gets a section "LoadingStringHelperchangesdefault_charset". The removal, and its entry indocs/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_charsetafter 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 thedocs/overview.mdstub, so expect small conflicts.🤖 Generated with Claude Code