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

Open
opened 2026-01-22 12:53:20 +01:00 by admin · 0 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:20 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#871