Skip to content

Commit 7ed5e76

Browse files
committed
THRIFT-5759: Remove mbstring.func_overload workaround from PHP library
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(). - 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. - 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.
1 parent d7e4bf2 commit 7ed5e76

26 files changed

Lines changed: 44 additions & 870 deletions

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # master
163163
with:
164164
php-version: ${{ matrix.php-version }}
165-
extensions: mbstring, intl, xml, curl
165+
extensions: intl, xml, curl
166166
ini-values: "error_reporting=E_ALL"
167167

168168
- name: Install Dependencies
@@ -928,7 +928,7 @@ jobs:
928928
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # master
929929
with:
930930
php-version: "8.3"
931-
extensions: mbstring, intl, xml, curl, sockets
931+
extensions: intl, xml, curl, sockets
932932
ini-values: "error_reporting=E_ALL"
933933

934934
- name: Install PHP dependencies

.github/workflows/sca.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
with:
5353
# Lowest supported PHP version
5454
php-version: "8.1"
55-
extensions: mbstring, xml, curl, pcntl
55+
extensions: xml, curl, pcntl
5656

5757
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
5858
with:

build/docker/ubuntu-focal/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ RUN apt-get install -y --no-install-recommends \
244244
php8.1 \
245245
php8.1-cli \
246246
php8.1-dev \
247-
php8.1-mbstring \
248247
php8.1-xml \
249248
php8.1-curl \
250249
php8.1-xdebug \

build/docker/ubuntu-jammy/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ RUN apt-get install -y --no-install-recommends \
233233
php8.1 \
234234
php8.1-cli \
235235
php8.1-dev \
236-
php8.1-mbstring \
237236
php8.1-xml \
238237
php8.1-curl \
239238
php8.1-xdebug \

build/docker/ubuntu-noble/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ RUN apt-get install -y --no-install-recommends \
232232
php8.3 \
233233
php8.3-cli \
234234
php8.3-dev \
235-
php8.3-mbstring \
236235
php8.3-xml \
237236
php8.3-curl \
238237
php8.3-xdebug \

lib/php/Makefile.am

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ phpfactory_DATA = \
6363
lib/Factory/TCompactProtocolFactory.php \
6464
lib/Factory/TJSONProtocolFactory.php \
6565
lib/Factory/TProtocolFactory.php \
66-
lib/Factory/TStringFuncFactory.php \
6766
lib/Factory/TTransportFactoryInterface.php \
6867
lib/Factory/TTransportFactory.php \
6968
lib/Factory/TFramedTransportFactory.php
@@ -106,12 +105,6 @@ phpserver_DATA = \
106105
lib/Server/TServerTransport.php \
107106
lib/Server/TSimpleServer.php
108107

109-
phpstringfuncdir = $(phpdir)/StringFunc
110-
phpstringfunc_DATA = \
111-
lib/StringFunc/Mbstring.php \
112-
lib/StringFunc/Core.php \
113-
lib/StringFunc/TStringFunc.php
114-
115108
phptransportdir = $(phpdir)/Transport
116109
phptransport_DATA = \
117110
lib/Transport/TBufferedTransport.php \
@@ -147,7 +140,6 @@ EXTRA_DIST = \
147140
src/ext/thrift_protocol/php_thrift_protocol.stub.php \
148141
src/ext/thrift_protocol/php_thrift_protocol_arginfo.h \
149142
src/Thrift.php \
150-
src/TStringUtils.php \
151143
coding_standards.md \
152144
thrift_protocol.ini \
153145
phpunit.xml \

lib/php/lib/Factory/TStringFuncFactory.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

lib/php/lib/Protocol/TBinaryProtocol.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
use Thrift\Type\TType;
2626
use Thrift\Exception\TProtocolException;
27-
use Thrift\Factory\TStringFuncFactory;
2827

2928
/**
3029
* Binary implementation of the Thrift protocol.
@@ -211,7 +210,7 @@ public function writeDouble($value)
211210

212211
public function writeString($value)
213212
{
214-
$len = TStringFuncFactory::create()->strlen($value);
213+
$len = strlen($value);
215214
$result = $this->writeI32($len);
216215
if ($len) {
217216
$this->trans_->write($value, $len);

lib/php/lib/Protocol/TCompactProtocol.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
use Thrift\Type\TType;
2626
use Thrift\Exception\TProtocolException;
27-
use Thrift\Factory\TStringFuncFactory;
2827

2928
/**
3029
* Compact implementation of the Thrift protocol.
@@ -136,7 +135,7 @@ public function getVarint($data)
136135
public function writeVarint($data)
137136
{
138137
$out = $this->getVarint($data);
139-
$result = TStringFuncFactory::create()->strlen($out);
138+
$result = strlen($out);
140139
$this->trans_->write($out, $result);
141140

142141
return $result;
@@ -364,7 +363,7 @@ public function writeDouble($value)
364363

365364
public function writeString($value)
366365
{
367-
$len = TStringFuncFactory::create()->strlen($value);
366+
$len = strlen($value);
368367
$result = $this->writeVarint($len);
369368
if ($len) {
370369
$this->trans_->write($value, $len);
@@ -761,7 +760,7 @@ public function writeI64($value)
761760
}
762761
}
763762

764-
$ret = TStringFuncFactory::create()->strlen($out);
763+
$ret = strlen($out);
765764
$this->trans_->write($out, $ret);
766765

767766
return $ret;

lib/php/lib/StringFunc/Core.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)