Skip to content

THRIFT-5759: Remove mbstring.func_overload workaround from PHP library#3445

Open
sveneld wants to merge 1 commit intoapache:masterfrom
sveneld:THRIFT-5759
Open

THRIFT-5759: Remove mbstring.func_overload workaround from PHP library#3445
sveneld wants to merge 1 commit intoapache:masterfrom
sveneld:THRIFT-5759

Conversation

@sveneld
Copy link
Copy Markdown
Contributor

@sveneld sveneld commented May 3, 2026

Removes the TStringFunc abstraction whose only purpose was to work around mbstring.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 returns false. This PR rips out the dead code.

This is not a behavior change on PHP 8.1+: TStringFuncFactory::create()->strlen($x) and native strlen($x) already return the same byte count, which is what Thrift's binary protocols require. The Thrift code generator does not emit any TStringFunc* references, so generated user code is unaffected.

What changed

  • Deleted Thrift\Factory\TStringFuncFactory, Thrift\StringFunc\{Core, Mbstring, TStringFunc}, and the legacy non-namespaced lib/php/src/TStringUtils.php.
  • Replaced 30+ TStringFuncFactory::create()->strlen/substr call sites in lib/Transport/* and lib/Protocol/* with native strlen() / substr().
  • Initialized TFramedTransport::$rBuf_ and $wBuf_ to '' (instead of the implicit null default) 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.
  • Removed the now-meaningless unit tests (TStringFuncFactoryTest, CoreTest, MbStringTest) and the obsolete mbstring.func_overload=0 ini override in src/ext/thrift_protocol/run-tests.php.
  • Added 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 over TMemoryBuffer to exercise the rBuf_ exhaustion path.
  • No mb_* calls remain anywhere in lib/php, test/php, the tutorial, or the C extension — mbstring is therefore dropped from build.yml, sca.yml, and the focal/jammy/noble Dockerfiles.
  • Updated lib/php/Makefile.am to drop the phpstringfuncdir block and the src/TStringUtils.php distribution entry; src/Thrift.php no longer includes the deleted file.

Diff: 27 files changed, +171 / −873.


  • Did you create an Apache Jira ticket? — THRIFT-5759
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"? — yes
  • Did you squash your changes to a single commit? — single commit d25e8eaa
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"? — no breaking change. The removed classes (Thrift\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 native strlen()/substr(). Behavior is identical for any caller on PHP 8.1+.
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources. — N/A, this PR is code.

@mergeable mergeable Bot added php build and general CI cmake, automake and build system changes github_actions Pull requests that update GitHub Actions code labels May 3, 2026
@sveneld sveneld marked this pull request as ready for review May 3, 2026 19:04
@sveneld sveneld requested review from Jens-G, fishy and jimexist as code owners May 3, 2026 19:04
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build and general CI cmake, automake and build system changes github_actions Pull requests that update GitHub Actions code php

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant