DDC-705: Using a named parameter in multiple places doesn't work #873

Closed
opened 2026-01-22 12:53:24 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 20, 2010).

Jira issue originally created by user jakajancar:

The following won't work:

$qb->andWhere('(a.campaign IS NOT NULL AND (cmp.user IS NULL OR cmp.user = :currentUser) OR a.previewTarget IS NOT NULL AND pt.user = :currentUser)')
   ->setParameter('currentUser', $currentUser);

The following will, but seems needlessly complex:

$qb->andWhere('(a.campaign IS NOT NULL AND (cmp.user IS NULL OR cmp.user = :currentUserA) OR a.previewTarget IS NOT NULL AND pt.user = :currentUserB)')
   ->setParameter('currentUserA', $currentUser)
   ->setParameter('currentUserB', $currentUser);

I would expect a named parameter to behave like a constant. I should be able to define it once, and then use it multiple times.

Also, I would like to be able to set the same parameter multiple times, so if multiple pieces of code set :currentUser that isn't a problem, unless they're different (in which case I'd expect an error like ":currentUser bound to two different values").

Originally created by @doctrinebot on GitHub (Jul 20, 2010). Jira issue originally created by user jakajancar: The following won't work: ``` $qb->andWhere('(a.campaign IS NOT NULL AND (cmp.user IS NULL OR cmp.user = :currentUser) OR a.previewTarget IS NOT NULL AND pt.user = :currentUser)') ->setParameter('currentUser', $currentUser); ``` The following will, but seems needlessly complex: ``` $qb->andWhere('(a.campaign IS NOT NULL AND (cmp.user IS NULL OR cmp.user = :currentUserA) OR a.previewTarget IS NOT NULL AND pt.user = :currentUserB)') ->setParameter('currentUserA', $currentUser) ->setParameter('currentUserB', $currentUser); ``` I would expect a named parameter to behave like a constant. I should be able to define it once, and then use it multiple times. Also, I would like to be able to set the same parameter multiple times, so if multiple pieces of code set :currentUser that isn't a problem, unless they're different (in which case I'd expect an error like ":currentUser bound to two different values").
admin added the Bug label 2026-01-22 12:53:24 +01:00
admin closed this issue 2026-01-22 12:53:24 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 26, 2010):

Comment created by @guilhermeblanco:

The Doctrine behavios is expected and correct.
Each parameter is atomic and can only be used once.

There is not way to implement it other way (AFAIK), but if you come with a patch... who knows! =)

Regards,

@doctrinebot commented on GitHub (Jul 26, 2010): Comment created by @guilhermeblanco: The Doctrine behavios is expected and correct. Each parameter is atomic and can only be used once. There is not way to implement it other way (AFAIK), but if you come with a patch... who knows! =) Regards,
Author
Owner

@doctrinebot commented on GitHub (Jul 26, 2010):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jul 26, 2010): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (May 9, 2012):

Comment created by holtkamp:

Seems to be resolved by this fix: http://www.doctrine-project.org/jira/browse/DDC-1040

@doctrinebot commented on GitHub (May 9, 2012): Comment created by holtkamp: Seems to be resolved by this fix: http://www.doctrine-project.org/jira/browse/[DDC-1040](http://www.doctrine-project.org/jira/browse/DDC-1040)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#873