Skip to content

THRIFT-6000: Add native types to PHP JSON protocol helpers and contexts#3479

Merged
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-6000
May 15, 2026
Merged

THRIFT-6000: Add native types to PHP JSON protocol helpers and contexts#3479
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-6000

Conversation

@sveneld
Copy link
Copy Markdown
Contributor

@sveneld sveneld commented May 14, 2026

Type the remaining untyped methods in TJSONProtocol, TSimpleJSONProtocol, their JSON/SimpleJSON Context classes, LookaheadReader, and CollectionMapKeyException. All internal/protected helpers; no public API change beyond the signature tightening.

Typed methods

TJSONProtocol:

  • getTypeNameForTypeID(int $typeID): string
  • getTypeIDForTypeName(string $name): int
  • pushContext(BaseContext $c): void
  • __construct(TTransport $trans)
  • reset(): void
  • readJSONSyntaxChar(string $b): void
  • writeJSONString(mixed $b): void
  • writeJSONInteger, writeJSONObjectStart/End/ArrayStart/End: return : void
  • readJSONString(bool $skipContext): mixed
  • readJSONNumericChars(): string
  • readJSONInteger(): int, readJSONIntegerAsString(): string, readJSONDouble(): float
  • readJSONObjectStart/End/ArrayStart/End: return : void

TSimpleJSONProtocol:

  • pushWriteContext(Context $c): void
  • popWriteContext(): void — returns a fresh Context() on stack underflow (matches the non-null property type, parallels TJSONProtocol's BaseContext fallback)
  • assertContextIsNotMapKey(string $invalidKeyType): void
  • writeJSONString(mixed $b): void, writeJSONInteger(int $num): void

Context classes (all return/param-typed):

  • JSON\BaseContext, ListContext, PairContext
  • JSON\LookaheadReader (read(): string, peek(): string)
  • SimpleJSON\Context, ListContext, MapContext, StructContext
  • SimpleJSON\CollectionMapKeyException::__construct(?string $message = null)

Validation (Docker thrift-php-dev:local)

  • phpcs — 0 errors
  • phpstan (level 5) — 0 errors
  • phpunit Unit Suite — 635 tests, 0 failures
  • phpunit Integration Suite — 108 tests, 0 failures

Follow-up to THRIFT-5999 within the umbrella THRIFT-5960.

  • Apache Jira ticket — THRIFT-6000
  • PR title follows the pattern "THRIFT-NNNN: …"
  • Squashed to a single commit
  • No behaviour changes; pure typing pass on internal/protected helpers

Generated-by: Claude Opus 4.7

Client: php

Type the remaining untyped methods in TJSONProtocol, TSimpleJSONProtocol,
their JSON/SimpleJSON Context classes, LookaheadReader, and
CollectionMapKeyException. All internal/protected helpers; no public API
change beyond the signature tightening.

Typed:
- TJSONProtocol::getTypeNameForTypeID(int $typeID): string
- TJSONProtocol::getTypeIDForTypeName(string $name): int
- TJSONProtocol::pushContext(BaseContext $c): void
- TJSONProtocol::__construct(TTransport $trans)
- TJSONProtocol::reset(): void
- TJSONProtocol::readJSONSyntaxChar(string $b): void
- TJSONProtocol::writeJSONString(mixed $b): void
- TJSONProtocol::writeJSONInteger(int $num): void  (return only)
- TJSONProtocol::writeJSONObjectStart/End/ArrayStart/End(): void
- TJSONProtocol::readJSONString(bool $skipContext): mixed
- TJSONProtocol::readJSONNumericChars(): string
- TJSONProtocol::readJSONInteger(): int
- TJSONProtocol::readJSONIntegerAsString(): string
- TJSONProtocol::readJSONDouble(): float
- TJSONProtocol::readJSONObjectStart/End/ArrayStart/End(): void
- TSimpleJSONProtocol::pushWriteContext(Context $c): void
- TSimpleJSONProtocol::popWriteContext(): void  (returns to default Context()
  on stack underflow rather than null, matching the non-null property type)
- TSimpleJSONProtocol::assertContextIsNotMapKey(string $invalidKeyType): void
- TSimpleJSONProtocol::writeJSONString(mixed $b): void
- TSimpleJSONProtocol::writeJSONInteger(int $num): void
- JSON\\BaseContext, ListContext, PairContext, LookaheadReader,
  SimpleJSON\\Context, ListContext, MapContext, StructContext:
  all read()/write()/escapeNum()/isMapKey()/__construct() typed.
- CollectionMapKeyException::__construct(?string $message = null)

Follow-up to THRIFT-5999 within the umbrella THRIFT-5960
(PHP modernization).

Generated-by: Claude Opus 4.7
@mergeable mergeable Bot added the php label May 14, 2026
@sveneld sveneld marked this pull request as ready for review May 15, 2026 05:50
@sveneld sveneld merged commit 834a00c into apache:master May 15, 2026
94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant