sveneld opened a new pull request, #3473:
URL: https://github.com/apache/thrift/pull/3473

   Phase **G3** of the 
[THRIFT-5960](https://issues.apache.org/jira/browse/THRIFT-5960) PHP 
modernization. The PHP code generator now emits native PHP types on struct 
property declarations and the constructor parameter.
   
   **Before → After:**
   
   ```php
   - public $errorCode = null;
   - public $message = null;
   - public $struct_thing = null;
   - public function __construct($vals = null)
   + public ?int $errorCode = null;
   + public ?string $message = null;
   + public ?\Basic\ThriftTest\Xtruct $struct_thing = null;
   + public function __construct(?array $vals = null)
   ```
   
   **Thrift → PHP type mapping** (all fields default nullable since Thrift 
field semantics admit unset):
   
   | Thrift | PHP |
   |---|---|
   | `bool` | `?bool` |
   | `byte` / `i8` / `i16` / `i32` / `i64` | `?int` |
   | `double` | `?float` |
   | `string` / `binary` / `uuid` | `?string` |
   | `enum` | `?int` |
   | `list<T>` / `set<T>` / `map<K,V>` | `?array` |
   | `struct` / `exception` | `?\Namespace\ClassName` |
   
   A new helper `type_to_native(t_type*)` centralises the mapping. It returns 
the bare type name (without `?`) so the caller can place the nullable marker; 
for now both field and parameter emission sites pin to `?T`.
   
   **Exception edge case:**
   
   Exception subclasses inherit `$message` and `$code` (untyped) from 
`\Exception`, and PHP forbids re-typing an inherited property. The generator 
skips native-type emission for those two field names when the class is a Thrift 
exception, leaving them as `public $message = null;` to satisfy the inherited 
contract.
   
   **Generator fixtures regeneration:**
   
   `lib/php/test/Resources/packages/` is git-ignored and regenerated by `make 
stubs` in CI before tests run. No fixture files appear in this diff.
   
   **Validation (Docker `thrift/thrift-build:ubuntu-focal` + 
`thrift-php-dev:local`):**
   - Built compiler with the patched generator.
   - Regenerated all 6 fixture variants (~435 PHP files) — every struct now has 
typed properties and a typed `__construct(?array $vals = null)`.
   - `phpcs` — 0 errors.
   - `phpstan` (level 1) — 0 errors.
   - `phpunit` Unit Suite — 635 tests, 0 failures.
   - `phpunit` Integration Suite — 108 tests, 0 failures.
   
   **Completes phase G** of the umbrella ticket. Subsequent work on the lib 
side covers `D` (Transport hierarchy types) and `H` (phpstan ratchet).
   
   - [x] Did you create an Apache Jira ticket? — 
[THRIFT-5991](https://issues.apache.org/jira/browse/THRIFT-5991)
   - [x] PR title follows the pattern "THRIFT-NNNN: describe my issue"
   - [x] Squashed to a single commit
   - [ ] Did you do your best to avoid breaking changes? — yes for library 
users (`lib/php/lib/*` is untouched); any third-party generated PHP code from 
an older Thrift compiler will need to be regenerated to gain the typed 
properties, but the old generated code is still valid PHP and the lib side 
accepts it.
   
   Generated-by: Claude Opus 4.7
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to