Binding parameters optimisation for BackedEnum (array of BackedEnum values) #7331

Open
opened 2026-01-22 15:50:04 +01:00 by admin · 1 comment
Owner

Originally created by @AlexMinaev19 on GitHub (Feb 29, 2024).

Feature Request

According to the documentation, we can pass integers, arrays of strings/integers, DateTime instances, and managed entities to the setParameter method (or to the constructor of Doctrine\ORM\Query\Parameter class). It's not a full list, because we can pass also BackedEnum or array of BackedEnum values. Doctrine automatically infers which type you are setting as value.

Also, the documentation says the following:

Even though passing DateTime instance is allowed, it impacts performance
as by default there is an attempt to load metadata for object, and if it's not found,
type is inferred from the original value.

Unfortunately, the current implementation of supporting BackedEnum as parameters (was added by PR) does not allow specifying the type of parameter manually to make performance optimization. If you try to specify Doctrine\DBAL\Types\Type::STRING, you get an exception.

Q A
New Feature yes
RFC yes
BC Break no

Summary

It would be nice to add support for explicitly passing type for BackedEnum parameters:

  • StringBackedEnum - Doctrine\DBAL\Types\Type::STRING
  • IntBackedEnum - Doctrine\DBAL\Types\Type::INTEGER
  • array<array-key, StringBackedEnum> - Doctrine\DBAL\ArrayParameterType::STRING
  • array<array-key, IntBackedEnum> - Doctrine\DBAL\ArrayParameterType::INTEGER
Originally created by @AlexMinaev19 on GitHub (Feb 29, 2024). ### Feature Request According to the documentation, we can pass integers, arrays of strings/integers, DateTime instances, and managed entities to the `setParameter` method (or to the constructor of `Doctrine\ORM\Query\Parameter` class). It's not a full list, because we can pass also `BackedEnum` or `array` of `BackedEnum` values. Doctrine automatically infers which type you are setting as value. Also, the documentation says the following: > Even though passing DateTime instance is allowed, it impacts performance as by default there is an attempt to load metadata for object, and if it's not found, type is inferred from the original value. Unfortunately, the current implementation of supporting `BackedEnum` as parameters (was added by [PR](https://github.com/doctrine/orm/pull/9373)) does not allow specifying the type of parameter manually to make performance optimization. If you try to specify `Doctrine\DBAL\Types\Type::STRING`, you get an exception. | Q | A |------------ | ------ | New Feature | yes | RFC | yes | BC Break | no #### Summary It would be nice to add support for explicitly passing type for `BackedEnum` parameters: - `StringBackedEnum` - `Doctrine\DBAL\Types\Type::STRING` - `IntBackedEnum` - `Doctrine\DBAL\Types\Type::INTEGER` - `array<array-key, StringBackedEnum>` - `Doctrine\DBAL\ArrayParameterType::STRING` - `array<array-key, IntBackedEnum>` - `Doctrine\DBAL\ArrayParameterType::INTEGER`
Author
Owner
@wmouwen commented on GitHub (Jul 7, 2025): Related - #10788 - #12063
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7331