THRIFT-5759: Remove mbstring.func_overload workaround from PHP library#3445
Open
sveneld wants to merge 1 commit intoapache:masterfrom
Open
THRIFT-5759: Remove mbstring.func_overload workaround from PHP library#3445sveneld wants to merge 1 commit intoapache:masterfrom
sveneld wants to merge 1 commit intoapache:masterfrom
Conversation
Client: php
The mbstring.func_overload PHP ini setting was deprecated in PHP 7.2
and removed in PHP 8.0. Since THRIFT-5956 raised the project's minimum
PHP version to 8.1, the TStringFunc abstraction guarding against this
setting has been functionally unreachable in every supported runtime
(ini_get('mbstring.func_overload') always returns false). This removes
the dead code; native strlen()/substr() already return byte counts on
PHP 8.1+, which is what Thrift's binary protocols need.
- Delete Thrift\Factory\TStringFuncFactory, Thrift\StringFunc\{Core,
Mbstring, TStringFunc}, and legacy lib/php/src/TStringUtils.php.
- Replace 30+ TStringFuncFactory::create()->strlen/substr call sites
in lib/Transport/* and lib/Protocol/* with native strlen()/substr().
- Initialize TFramedTransport::$rBuf_ and $wBuf_ to '' (instead of the
default null) and reset $rBuf_ to '' after a frame is consumed, so
the new direct strlen()/substr() calls never receive null and never
trigger the PHP 8.1 "passing null to parameter of type string is
deprecated" warning that the deleted Core wrapper used to mask via
(string)$str casts.
- Drop the corresponding unit tests (TStringFuncFactoryTest, CoreTest,
MbStringTest) and remove the obsolete mbstring.func_overload=0 ini
override from src/ext/thrift_protocol/run-tests.php.
- Add a regression test (StringByteCountTest) that pins the byte-count
contract: TBinaryProtocol/TCompactProtocol round-trip non-ASCII UTF-8
payloads (Cyrillic, Arabic, CJK, Malayalam, emoji, etc.) intact, and
the on-the-wire i32 length prefix matches the byte length, not the
character count. The test also covers TFramedTransport on top of
TMemoryBuffer to exercise the rBuf_ exhaustion path.
- No mb_* function calls remain anywhere in lib/php, test/php, the
tutorial, or the C extension, so drop mbstring from build.yml,
sca.yml, and the focal/jammy/noble Dockerfiles.
- Update lib/php/Makefile.am to drop the phpstringfuncdir block and
the src/TStringUtils.php distribution entry; src/Thrift.php no
longer includes the deleted TStringUtils.php.
The Thrift code generator does not emit any TStringFunc* references,
so generated user code is unaffected.
Generated-by: Claude Opus 4.7 <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.
Removes the
TStringFuncabstraction whose only purpose was to work aroundmbstring.func_overload, a PHP ini setting that was deprecated in PHP 7.2 and removed in PHP 8.0. Since THRIFT-5956 raised the project's minimum PHP version to 8.1, the workaround has been functionally unreachable on every supported runtime —ini_get('mbstring.func_overload')always returnsfalse. This PR rips out the dead code.This is not a behavior change on PHP 8.1+:
TStringFuncFactory::create()->strlen($x)and nativestrlen($x)already return the same byte count, which is what Thrift's binary protocols require. The Thrift code generator does not emit anyTStringFunc*references, so generated user code is unaffected.What changed
Thrift\Factory\TStringFuncFactory,Thrift\StringFunc\{Core, Mbstring, TStringFunc}, and the legacy non-namespacedlib/php/src/TStringUtils.php.TStringFuncFactory::create()->strlen/substrcall sites inlib/Transport/*andlib/Protocol/*with nativestrlen()/substr().TFramedTransport::$rBuf_and$wBuf_to''(instead of the implicitnulldefault) and reset$rBuf_to''after a frame is consumed, so the new directstrlen()/substr()calls never receivenulland never trigger the PHP 8.1 "passing null to parameter of type string is deprecated" warning that the deletedCorewrapper used to mask via(string)$strcasts.TStringFuncFactoryTest,CoreTest,MbStringTest) and the obsoletembstring.func_overload=0ini override insrc/ext/thrift_protocol/run-tests.php.StringByteCountTestthat pins the byte-count contract:TBinaryProtocol/TCompactProtocolround-trip non-ASCII UTF-8 payloads (Cyrillic, Arabic, CJK, Malayalam, emoji, etc.) intact, and the on-the-wire i32 length prefix matches the byte length, not the character count. The test also coversTFramedTransportoverTMemoryBufferto exercise therBuf_exhaustion path.mb_*calls remain anywhere inlib/php,test/php, the tutorial, or the C extension —mbstringis therefore dropped frombuild.yml,sca.yml, and thefocal/jammy/nobleDockerfiles.lib/php/Makefile.amto drop thephpstringfuncdirblock and thesrc/TStringUtils.phpdistribution entry;src/Thrift.phpno longer includes the deleted file.Diff: 27 files changed, +171 / −873.
d25e8eaaThrift\Factory\TStringFuncFactory,Thrift\StringFunc\*) only existed to detect a PHP feature that no longer exists; on every supported runtime they were no-op wrappers around nativestrlen()/substr(). Behavior is identical for any caller on PHP 8.1+.[skip ci]anywhere in the commit message to free up build resources. — N/A, this PR is code.