Skip to content

THRIFT-5985: Add native method types to PHP Exception hierarchy#3465

Merged
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-5985
May 12, 2026
Merged

THRIFT-5985: Add native method types to PHP Exception hierarchy#3465
sveneld merged 1 commit into
apache:masterfrom
sveneld:THRIFT-5985

Conversation

@sveneld
Copy link
Copy Markdown
Contributor

@sveneld sveneld commented May 12, 2026

Type the public surface of the PHP exception hierarchy in lib/php/lib/Exception/.

Changes:

  • TException::__construct(string|array|null $p1 = null, int|array $p2 = 0) — preserves the bridge constructor that accepts either standard Exception args (message, code) or Thrift Base spec/vals. Union types capture the polymorphism explicitly.
  • TApplicationException — typed __construct(?string $message = null, int $code = 0) plus read(TProtocol $output): int and write(TProtocol $output): int. Added use Thrift\Protocol\TProtocol;.
  • TProtocolException — typed __construct(?string $message = null, int $code = 0).
  • TTransportException — typed __construct(?string $message = null, int $code = 0).

Out of scope:

The internal serialization helpers in TException (readMap, readList, readStruct, writeMap, writeList, writeStruct) mirror the same untyped helpers on TBase. Typing those is a separate concern (would need to be applied consistently across both classes and would touch broader by-ref dynamic-dispatch behavior).

Validation (Docker thrift-php-dev:local):

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

Part of the umbrella ticket THRIFT-5960 (PHP modernization).

  • Did you create an Apache Jira ticket? — THRIFT-5985
  • PR title follows the pattern "THRIFT-NNNN: describe my issue"
  • Squashed to a single commit
  • No breaking changes (subclass narrowing string|null from string|array|null is a no-op for the standard new TXxx($msg, $code) call pattern; the bridge new TException($spec, $vals) still works at the base class)

Generated-by: Claude Opus 4.7

@mergeable mergeable Bot added the php label May 12, 2026
Client: php

Type the public surface of the PHP exception hierarchy in
lib/php/lib/Exception/:

- TException::__construct(string|array|null $p1 = null, int|array $p2 = 0)
  — preserves the bridge constructor that accepts either standard
  Exception args (message, code) or Thrift Base spec/vals via union
  types.

- TApplicationException — typed __construct(?string $message, int $code)
  plus read()/write() with TProtocol parameter and int return.

- TProtocolException — typed __construct(?string $message, int $code).

- TTransportException — typed __construct(?string $message, int $code).

The internal serialization helpers (readMap/writeMap/readList/...)
mirror TBase's untyped helpers and are left untouched here; typing
those is a separate concern.

Part of the umbrella ticket THRIFT-5960 (PHP modernization).

Generated-by: Claude Opus 4.7
@sveneld sveneld marked this pull request as ready for review May 12, 2026 19:47
@sveneld sveneld merged commit 279c1fd into apache:master May 12, 2026
93 of 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