THRIFT-5980: Add native method types to PHP Transport hierarchy#3460
Merged
Conversation
071bec3 to
84c602a
Compare
Client: php Migrate the public methods on lib/php/lib/Transport/ from PHPDoc @param/@return annotations to native parameter and return types. This completes the typing trajectory for the Transport subtree started by THRIFT-5976 (properties), THRIFT-5977 (ctor promotion), THRIFT-5978 (strict_types) and THRIFT-5979 (Server + Factory method types). Library: * TTransport abstract: isOpen(): bool, open(): void, close(): void, read(int): string, readAll(int): string, write(string): void, flush(): void. * TSocket / TSSLSocket / TSocketPool: open/close/read/write/flush typed; setSendTimeout/setRecvTimeout/setDebug/setNumRetries/etc typed; getHost /getPort typed; setHandle typed return. * TBufferedTransport / TFramedTransport / TMemoryBuffer / TNullTransport / TPhpStream: all method overrides typed to match the abstract. * TFramedTransport::write keeps the legacy `?int $len = null` optional parameter so existing internal callers in TBinaryProtocol / TCompactProtocol still type-check; the non-write path now delegates with just the buffer. * TCurlClient / THttpClient: read/write/flush/close/open typed; timeout setters typed as ?float (int widens automatically); addHeaders typed array. Full NaN / +Infinity / -Infinity round-trip for the JSON protocols: * TJSONProtocol now writes all three IEEE-754 sentinels as the conventional quoted tokens ("NaN", "Infinity", "-Infinity") matching the Java and C++ TJSONProtocol implementations; the read side gains a "-Infinity" branch so the round-trip is symmetric. Token literals are hoisted to TOKEN_NAN / TOKEN_POS_INFINITY / TOKEN_NEG_INFINITY consts on TJSONProtocol following the existing NAME_* convention, so writer and reader can never drift. * TSimpleJSONProtocol reuses TJSONProtocol's token constants and emits the same three tokens for its write-only path. * The previously corrupted `{"dbl":}` / `{"thing":}` output for non- finite doubles (locked into integration tests with #TODO markers) is fixed; integration tests now assert the correct round-trippable strings, plus a -Infinity case is added on both read and write paths. Side fixes surfaced by typed transports: * TSocket::setSendTimeout/setRecvTimeout switched to intdiv() so the typed int property assignment is exact (floor returns float). * TCurlClient::$timeout / $connectionTimeout and THttpClient::$timeout tightened from float|int|null to ?float (int widens automatically). * TBufferedTransport / TFramedTransport: stale "wBuf_" comments referring to the old C++-style property name dropped. Tests: * TBinaryProtocolTest / TCompactProtocolTest / TBufferedTransportTest / TFramedTransportTest: dropped `->willReturn(N)` from mocks of the now-void write/open/close/flush. Behavior unchanged; PHPUnit refuses to mock returning a value for void methods. * TFramedTransportTest::testWrite mock with('12345', 5) updated to with('12345') after the non-write path now passes only the buffer. * TCurlClientTest timeout data provider switched to float literals (10.0 instead of 10) to match the now-typed ?float properties. * TJSONProtocolTest gains round-trip cases for NaN, +Infinity, and -Infinity through writeAndReadScalarDataProvider. Generated-by: Claude Opus 4.7
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.
Migrates the public methods on
lib/php/lib/Transport/from PHPDoc@param/@returnannotations to native parameter and return types, plus fixes a long-standing correctness bug inTJSONProtocol::writeJSONDoublethat strict-mode typing surfaced.Completes the typing trajectory for the Transport subtree started by THRIFT-5976 (properties), THRIFT-5977 (ctor promotion), THRIFT-5978 (
strict_types) and THRIFT-5979 (Server + Factory method types).Library
TTransportabstract —isOpen(): bool,open(): void,close(): void,read(int): string,readAll(int): string,write(string): void,flush(): void.TSocket/TSSLSocket/TSocketPool— open/close/read/write/flush typed; setSendTimeout / setRecvTimeout / setDebug / setNumRetries / etc typed; getHost / getPort typed; setHandle return typed.TBufferedTransport/TFramedTransport/TMemoryBuffer/TNullTransport/TPhpStream— all method overrides typed to match the abstract.TFramedTransport::writekeeps the legacy?int $len = nulloptional parameter so existing internal callers inTBinaryProtocol/TCompactProtocolstill type-check; the non-write path now delegates with just the buffer.TCurlClient/THttpClient— read/write/flush/close/open typed; timeout setters typed as?float(int widens automatically);addHeaderstypedarray.NaN / Infinity round-trip fix
TJSONProtocol::readJSONDoublealready parses the quoted strings"NaN"→NANand"Infinity"→INF(Thrift JSON convention), butwriteJSONDoublepreviously calledjson_encode($num)which returnsfalsefor NaN/INF; once typedwrite(string)rejectsfalse, this used to silently emit empty output ({"dbl":}) — locked into integration tests with a#TODO Should be fixed in futurecomment.Now writes the conventional quoted strings:
NAN→"NaN"INF→"Infinity"-INFinTJSONProtocol→TProtocolException::INVALID_DATA(the read side has no inverse).-INFinTSimpleJSONProtocol→"-Infinity"symmetrically (write-only protocol).The TODO is resolved; integration tests updated to assert the correct outputs.
Other side fixes surfaced by typing
TSocket::setSendTimeout/setRecvTimeout: switched fromfloor($timeout / 1000)tointdiv($timeout, 1000)so the typedintproperty assignment is exact (floorreturnsfloat).TCurlClient::$timeout/$connectionTimeoutandTHttpClient::$timeouttightened fromfloat|int|nullto?float(int widens automatically per PHP rules).Tests
TBinaryProtocolTest/TCompactProtocolTest/TBufferedTransportTest/TFramedTransportTest— dropped->willReturn(N)from mocks of the now-void write/open/close/flush. Behavior unchanged; PHPUnit refuses to mock returning a value for void methods.TFramedTransportTest::testWrite— mockwith('12345', 5)updated towith('12345')after the non-write path now passes only the buffer to the underlying transport.TCurlClientTest— timeout data provider switched to float literals (10.0instead of10) to match the now-typed?floatproperties.TJSONProtocolTest/TSimpleJSONProtocolTest— NaN / Infinity write assertions updated from the broken{"dbl":}/{"thing":}outputs to the correct round-trippable strings.Part of THRIFT-5960 — modernizing PHP runtime library typing.
TJSONProtocol::readJSONDouble; previously this path produced unreadable output, so callers depending on it were already broken.[skip ci]anywhere in the commit message to free up build resources. — N/A (code change)Generated-by: Claude Opus 4.7