[PR #9647] Add enumFallbackValue optional parameter for PHP enum types #11771

Closed
opened 2026-01-22 16:11:51 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/9647

State: closed
Merged: No


As proposed in https://github.com/doctrine/orm/issues/9433 I added the option to specify default value in case DB value is not castable to native PHP Enum.

The new option is called enumDefaultValue and can be either null or Enum of the same type as the PHP property.

Multiple cases are covered, e.g. if DB column is nullable, but enumDefaultValue is set to Suit::Spades and not null, in such case the PHP property will still be null if DB has null value, but will be Suit::Spades for any invalid value.

In case DB value is NOT nullable and enumDefaultValue is set to Suit::Spades, then if DB has empty value/null/invalid value then Suit::Spades will be used.

I encourage you to check the test, it explains the behavior.

In case enumDefaultValue is not specified, then no behavior change occurs and the bundle works just like before.

**Original Pull Request:** https://github.com/doctrine/orm/pull/9647 **State:** closed **Merged:** No --- As proposed in https://github.com/doctrine/orm/issues/9433 I added the option to specify default value in case DB value is not castable to native PHP Enum. The new option is called `enumDefaultValue` and can be either null or Enum of the same type as the PHP property. Multiple cases are covered, e.g. if DB column is nullable, but `enumDefaultValue` is set to `Suit::Spades` and not null, in such case the PHP property will still be null if DB has null value, but will be `Suit::Spades` for any invalid value. In case DB value is NOT nullable and `enumDefaultValue` is set to `Suit::Spades`, then if DB has empty value/null/invalid value then `Suit::Spades` will be used. I encourage you to check the test, it explains the behavior. In case `enumDefaultValue` is not specified, then no behavior change occurs and the bundle works just like before.
admin added the pull-request label 2026-01-22 16:11:51 +01:00
admin closed this issue 2026-01-22 16:11:51 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#11771