THRIFT-5977: Apply constructor property promotion in PHP runtime library#3456
Merged
Conversation
Client: php
Convert constructors that were pure 1:1 argument→property assignments
to PHP 8 promoted constructor parameters. Pure syntactic refactor with
no behavioural change.
Files (16):
* Factory/TBinaryProtocolFactory, Server/TServer, Server/TServerSocket,
ClassLoader/ThriftClassLoader, Transport/{TBufferedTransport,
TFramedTransport, TMemoryBuffer, THttpClient, TCurlClient, TSocket,
TSSLSocket, Server/TSSLServerSocket} — full or partial promotion.
* Protocol/{TBinaryProtocol, TMultiplexedProtocol},
StoredMessageProtocol — partial promote (parent::__construct kept).
Bonus fixes surfaced while promoting:
* TFramedTransport: drop the `?TTransport = null` nullable-fiction —
every method dispatches through `$this->transport->...` with no
null guard. Now `TTransport` (required); all in-repo call sites
already pass a transport.
* TSSLSocket / TSSLServerSocket previously bypassed `parent::__construct`
and assigned inherited properties directly. After 5976 typed those
parent properties this would leave `$persist` uninitialised in the
SSL classes. Now both delegate to parent and only initialise the
SSL-specific `$context`.
* TSocket: replace the `'error_log'` magic string with a public
`DEFAULT_DEBUG_HANDLER` class constant and switch the fallback to
`??` for null-default semantics.
* THttpClient / TCurlClient: simplify the URI prefix-normalisation
with `str_starts_with()`.
* The duplicated SSL host-prefix helper is extracted as a small
private `ensureSslHostPrefix()` method on each SSL class
(TSSLSocket and TSSLServerSocket) so the bare `parent::__construct(
$this->ensureSslHostPrefix($host), …)` call reads cleanly.
Verified inside docker (PHP 8.4 + composer 2 + phpstan 1.12 + phpunit 13):
composer phpstan OK (level 1, baseline unchanged)
vendor/bin/phpcs OK
phpunit Unit suite 629 tests, 1907 assertions, 0 errors
phpunit Integration 106 tests, 166 assertions, 0 errors
Parent: THRIFT-5960
Generated-by: Claude Opus 4.7 (1M context) <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
Follow-up to THRIFT-5976 (typed properties). After that work, many constructors in
lib/php/lib/were pure 1:1 argument→property assignments — exactly what PHP 8 constructor property promotion replaces. Apply promotion across the library: cleaner declarations, no behavioural change, no LSP impact.JIRA: https://issues.apache.org/jira/browse/THRIFT-5977 (related to THRIFT-5960).
Scope
Full promote (ctor body becomes empty or a single parent call)
Factory/TBinaryProtocolFactory—strictRead,strictWrite.Server/TServer(6 properties) —processor,transport, four factory parameters.Server/TServerSocket—host,port(acceptTimeoutretained as a regular property, mutated viasetAcceptTimeout()).Transport/TMemoryBuffer—buf.Transport/TBufferedTransport—transport,rBufSize,wBufSize.Transport/TFramedTransport—transport,read,write.ClassLoader/ThriftClassLoader—apcu,apcu_prefix.Partial promote (body keeps
parent::__construct(...)or one non-trivial line)Protocol/TBinaryProtocol—strictRead,strictWrite;$transforwarded to parent.Protocol/TMultiplexedProtocol—serviceName;$protocolforwarded.StoredMessageProtocol—fname,mtype,rseqid;$protocolforwarded.Transport/TSocket—host,port,persist;debugHandlerretains the?: 'error_log'fallback in the body.Transport/THttpClient—host,port,scheme,context;urikeeps its prefix-normalisation in the body.Transport/TCurlClient—host,port,scheme; sameurilogic.Bonus fixes surfaced while promoting
Transport/TSSLSocketwas bypassingparent::__constructentirely. Now properly delegatesparent::__construct(self::getSSLHost($host), $port, false, $debugHandler), ensuring TSocket's promoted properties get initialised.getSSLHostmadeprivate staticsince it doesn't use$this.Server/TSSLServerSocket— same pattern:parent::__construct(self::getSSLHost($host), $port);getSSLHostmadepublic static.Out of scope (intentionally skipped)
TPhpStream— bitwise ($mode & MODE_R/MODE_W) ctor logic, not 1:1.TException,TApplicationException,TProtocolException,TTransportException) — dual-mode bridge constructor.TBase,TSimpleJSONProtocol,TJSONProtocol— non-trivial init bodies ($context = new Context(),$reader = new LookaheadReader(), conditionalspec/valsprocessing).TSocketPool— ctor builds$serversand normalises$ports; not 1:1.TBinaryProtocolAccelerated— passes through to parent unchanged after the parent promotion.Verification (PHP 8.4 / composer 2 / phpstan 1.12 / phpunit 13 in docker)
Checklist
TSSLSocketandTSSLServerSocketnow correctly callparent::__construct, which initialises previously-uninitialised inherited typed properties (no functional behaviour change for callers since the SSL classes overrode every method that read those properties).[skip ci]anywhere in the commit message to free up build resources.