Skip to content

Fix nullable PHP model hydration for empty strings#1440

Merged
ChiragAgg5k merged 2 commits intomasterfrom
fix/php-arrayserializable-nullable-enums
Apr 11, 2026
Merged

Fix nullable PHP model hydration for empty strings#1440
ChiragAgg5k merged 2 commits intomasterfrom
fix/php-arrayserializable-nullable-enums

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

  • normalize empty-string values to null during PHP model hydration when the generated property type is nullable
  • keep the change scoped to nullable non-builtin from()-hydrated values so optional enum/model fields no longer throw on wire-level "" sentinels

Context

The PHP generator now emits nullable model properties for some response fields, but the shared ArraySerializable hydrator still passed "" into Type::from(...). That causes hydration failures for nullable enum-like fields where the API uses an empty string as an unset sentinel.

Testing

  • docker run --rm -v $(pwd):/app -w /app php:8.3-cli php example.php php
  • composer lint-twig
  • vendor/bin/phpunit tests/PHP83Test.php

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 11, 2026

Greptile Summary

This PR adds a narrow three-line guard to ArraySerializable::hydrateValue that normalizes an empty-string wire value to null when the target type is nullable and exposes a from() method. The fix is correctly placed after the !method_exists guard (the ordering concern raised in the previous review thread has been addressed in the head commit), so it only fires for nullable, from()-backed non-builtin types.

Confidence Score: 5/5

Safe to merge — the fix is minimal, correctly scoped, and the prior guard-ordering concern is resolved.

Single-file change with a 3-line guard that is logically correct; previous reviewer concern about ordering was addressed in the refining commit; no other issues found.

No files require special attention.

Important Files Changed

Filename Overview
templates/php/src/Models/ArraySerializable.php.twig Adds a 3-line guard in hydrateValue that returns null for empty-string wire values when the parameter type is nullable and has a from() method; correctly placed after the method_exists guard.

Reviews (2): Last reviewed commit: "Scope nullable PHP hydration to from()-b..." | Re-trigger Greptile

Comment thread templates/php/src/Models/ArraySerializable.php.twig Outdated
@ChiragAgg5k ChiragAgg5k merged commit c92b460 into master Apr 11, 2026
1 of 2 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix/php-arrayserializable-nullable-enums branch April 11, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant