Skip to content

Hydration error for int-backed enums stored as string values in MySQL ENUM columns #12274

@TheBreaken

Description

@TheBreaken

Bug Report

Summary

When using PHP backed enums with Doctrine, a type mismatch between the database column and the PHP enum unexpectedly triggers an error.
This occurs when the database stores enum values as strings (e.g., MySQL ENUM or VARCHAR) but the PHP enum uses integers as its backed type.

Example use case: MySQL ENUM columns containing internal codes like 500 or 510 are stored as strings, while the corresponding PHP enum uses integer backed values.

Doctrine currently does not cast these values and fails when trying to hydrate the enum.

Current behavior

If the database column contains a value like "500" (string), but the PHP enum expects an integer (e.g., 500), Doctrine throws an error during hydration:

  • Doctrine does not cast the value
  • Doctrine tries to hydrate the enum using the string "500"
  • This results in a ValueError or similar enum resolution failure

Expected behavior

Doctrine should:

  • Detect that the enum’s backed type is int
  • Automatically cast the incoming database value to int when possible
  • Hydrate the enum correctly without error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions