Deprecate type inference in Query::setParameter #6584

Open
opened 2026-01-22 15:35:23 +01:00 by admin · 3 comments
Owner

Originally created by @beberlei on GitHub (Dec 6, 2020).

We should assume every object passed must be an entity or specify a $type as third argument. Only primitive types should work with type inference. A deprecation is in order to allow users. to migrate of this behavior.

Problems with type inference:

Originally created by @beberlei on GitHub (Dec 6, 2020). We should assume every object passed *must* be an entity *or* specify a $type as third argument. Only primitive types should work with type inference. A deprecation is in order to allow users. to migrate of this behavior. Problems with type inference: - Performance problems due to trying to load mapping files and failing https://github.com/doctrine/orm/issues/8113 - Ambiguities when inferring `DateTime`, to `datetime` or `datetime_utc`. https://github.com/doctrine/orm/issues/6443
admin added the Deprecation label 2026-01-22 15:35:23 +01:00
Author
Owner

@beberlei commented on GitHub (Dec 8, 2020):

In addition we should think about differentiating between setParameter for single valued paraemters and setParameterList for an array of values of the specified type. Then this could allow support for arrays of more complex types:

$dates = [new DateTime, new DateTime];
$query->setParameterList(1, $dates, "datetime");
@beberlei commented on GitHub (Dec 8, 2020): In addition we should think about differentiating between `setParameter` for single valued paraemters and `setParameterList` for an array of values of the specified type. Then this could allow support for arrays of more complex types: ``` $dates = [new DateTime, new DateTime]; $query->setParameterList(1, $dates, "datetime"); ```
Author
Owner

@beberlei commented on GitHub (May 1, 2021):

Needs more research

@beberlei commented on GitHub (May 1, 2021): Needs more research
Author
Owner

@sips-richard commented on GitHub (Apr 14, 2022):

The optional type argument on setParameter() and the baked in behaviour of inferType() for booleans and datetimes is confusing and sets the wrong expectation for consumers. I've just been digging into this to understand why these types were treated differently from other registered types. We will be updating our company coding standard to mandate that the type is always specified for consistency and clarity (obviously Connection::PARAM_STR_ARRAY etc. isn't ideal). I would welcome this change in Doctrine.

@sips-richard commented on GitHub (Apr 14, 2022): The optional type argument on setParameter() and the baked in behaviour of inferType() for booleans and datetimes is confusing and sets the wrong expectation for consumers. I've just been digging into this to understand why these types were treated differently from other registered types. We will be updating our company coding standard to mandate that the type is always specified for consistency and clarity (obviously Connection::PARAM_STR_ARRAY etc. isn't ideal). I would welcome this change in Doctrine.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6584