Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate type inference in Query::setParameter #8379

Open
beberlei opened this issue Dec 6, 2020 · 3 comments
Open

Deprecate type inference in Query::setParameter #8379

beberlei opened this issue Dec 6, 2020 · 3 comments

Comments

@beberlei
Copy link
Member

beberlei commented 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:

@beberlei beberlei added this to the 2.9.0 milestone Dec 6, 2020
@beberlei
Copy link
Member Author

beberlei commented 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
Copy link
Member Author

beberlei commented May 1, 2021

Needs more research

@greg0ire greg0ire removed this from the 2.10.0 milestone Oct 3, 2021
@sips-richard
Copy link

sips-richard commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants