Skip to content

Coerce scalar constructor properties without loss #24

Done

Description

@yuriizee

Current (2.x)

Generated hydrators run without strict_types, so PHP's own coercion applies to scalar constructor parameters without a cast:

Property Input Result
int "1.9", 1.9 1 (only a PHP deprecation)
int true 1
bool "false" true
int "abc" TypeError naming a library file

Decision needed

  • A (proposed): explicit lossless coercion in the generated code, only for scalar parameters without a cast. int ← int, a float with no fraction, a digit string in range; float ← int/float/numeric string; string ← string/int/float; bool ← bool and FILTER_VALIDATE_BOOL strings (1/0/true/false/on/off/yes/no/""). Anything else → DataHydrationException with the field name. Fast path stays one inline type check (is_int($v) ? $v : …); the slow path is a static helper.
  • B: declare(strict_types=1) in the generated code. Cheapest, but "5" → int becomes an error, which breaks form and query-string input.

Notes

Hot path change: benchmarks before/after are mandatory.

Done when

  • PR into 3.x, tests at 100% coverage, PHPStan and Pint clean
  • UPGRADE-3.0.md section matches the implemented behaviour
  • .claude/skills/migrate-from-v2-to-v3/SKILL.md step matches it
  • CHANGELOG.md [Unreleased] entry
  • Benchmarks before/after

Activity

  1. added this to the 3.0.0 milestone on Nov 27, 2026
  2. added
    breaking change
    on Nov 27, 2026
  3. added a commit that references this issue on Nov 27, 2026
    0dfb1f5
  4. yuriizee commented on Nov 27, 2026

    @yuriizee
    ContributorAuthor

    Merged into 3.x in #37.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking change

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions