mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
QueryBuilder::getQuery does not clone parameters, is this intended or a bug? #6222
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 @datadestroyd on GitHub (Apr 15, 2019).
Originally assigned to: @Ocramius on GitHub.
Bug Report
Summary
QueryBuilder::getQuerydoes not deep clone the parameters. I am unsure whether this is intended behavior or a bug. The docs don't mention it. However, I find it very counterintuitive.Current behavior
When calling
getQueryon aQueryBuilder, the parameters are copied into theQueryinstance. However, subsequently modifying parameters on the builder, e.g. to create another similar query, also modify the parameters in the previousQueryinstance.How to reproduce
Expected behavior
$queryA->getParameter('param')->getValue()should return'foo', not'bar'.@Ocramius commented on GitHub (Apr 15, 2019):
This is very much expected, since there is no guarantee that parameters are cloneable in first place. I agree that cloning the
ParameterCollectionwould be a good idea, but it is only applicable for3.x: consider sending a patch directly.Closing here meanwhile.
@datadestroyd commented on GitHub (Apr 16, 2019):
The collection is already being cloned. I am talking about the
Parameterinstances inside that collection. I didn't mean that the values themselves should be cloned. Like you said, that is not necessarily possible.So basically what I meant was that
$queryA->getParameter('param')should not return the sameParameterinstance as$queryB->getParameter('param'). Just a thought.