mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Hydration error for int-backed enums stored as string values in MySQL ENUM columns #7577
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @TheBreaken on GitHub (Nov 17, 2025).
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:
Expected behavior
Doctrine should:
@derrabus commented on GitHub (Nov 18, 2025):
No tests?
@TheBreaken commented on GitHub (Nov 18, 2025):
@derrabus I added now some tests in the PR https://github.com/doctrine/orm/pull/12275
@derrabus commented on GitHub (Nov 18, 2025):
Right. Sorry, I don't know how my review comment ended up on the bug report instead of the PR. 🙈
@TheBreaken commented on GitHub (Nov 27, 2025):
Hello @derrabus can you review the PR?