sveneld opened a new pull request, #3466: URL: https://github.com/apache/thrift/pull/3466
Add `declare(strict_types=1);` to every PHP file emitted by the PHP code generator (`t_php_generator`). Placed after the autogen license docblock and before the `namespace` declaration, matching PSR-12 header order. **Why the cast helper was needed:** PHP arrays silently coerce numeric-string keys to `int` (e.g. `'123'` becomes `123`) when iterated via `foreach … as $k => $v`. Under strict types the typed `writeXxx()` calls in the library (typed in [THRIFT-5981](https://issues.apache.org/jira/browse/THRIFT-5981)) then refuse the coerced value. Cast the iterator variable back to its declared base type before the write call in two places that take the array key: - `generate_serialize_map_element` — map keys. - `generate_serialize_set_element` — scalar set elements (sets are stored as `[$elem => true]`, so the element is the array key). The cast logic is centralized in a single new helper, `emit_array_key_recast`, which only acts on `TYPE_STRING` and the int family. Other base types either can't be array keys (struct/container) or round-trip through PHP's coercion losslessly. **Fixtures regeneration:** The fixtures under `lib/php/test/Resources/packages/` are git-ignored (per `.gitignore`) and regenerated by `make stubs` in CI before tests run. No fixture files appear in this diff. **Validation (local Docker `thrift/thrift-build:ubuntu-focal` + `thrift-php-dev:local`):** - Built compiler with patched generator. - Regenerated all 6 fixture variants (435 PHP files total). - Each generated file now starts with `declare(strict_types=1);` after the docblock. - `phpcs` — 0 errors (full project including generated fixtures). - `phpstan` (level 1) — 0 errors. - `phpunit` Unit Suite — 635 tests, 0 failures. - `phpunit` Integration Suite — 108 tests, 0 failures. **Scope:** This is phase **G1** of the [THRIFT-5960](https://issues.apache.org/jira/browse/THRIFT-5960) umbrella PHP modernization (PHP generator regen). Subsequent phases (separate tickets): - **G2** — emit native return types on generated `read()` / `write()` / `getName()` / validators. - **G3** — emit native parameter & property types on the generated constructor and property declarations. - [x] Did you create an Apache Jira ticket? — [THRIFT-5986](https://issues.apache.org/jira/browse/THRIFT-5986) - [x] PR title follows the pattern "THRIFT-NNNN: describe my issue" - [x] Squashed to a single commit - [x] No breaking changes (only generated code is affected; library API untouched) 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]
