EntityRepository#count() should support Criteria as parameter #7573

Open
opened 2026-01-22 15:53:41 +01:00 by admin · 0 comments
Owner

Originally created by @jurchiks on GitHub (Nov 8, 2025).

Feature Request

What

https://github.com/doctrine/orm/blob/3.5.x/src/EntityRepository.php#L138
EntityRepository#count() calls EntityPersister#count(), which defines itself as public function count(array|Criteria $criteria = []): int. This methos has two implementations, AbstractEntityPersister#count() and BasicEntityPersister#count(), both of which have the same method signature.
However, EntityRepository#count() is defined as public function count(array $criteria = []): int, completely discarding the Criteria option.

Please add Criteria to this parameter to make it match the interface and improve UX.

Why

Because it makes sense.
Instead of having to write a custom EntityRepository method, users could write something like this:

$newUsersThisMonth = $em->getRepository(User::class)->count(
    Criteria::expr()->gte('createdAt', new DateTime('midnight first day of this month'))
);

How

-public function count(array $criteria = []): int
+public function count(array|Criteria $criteria = []): int
Originally created by @jurchiks on GitHub (Nov 8, 2025). ### Feature Request #### What https://github.com/doctrine/orm/blob/3.5.x/src/EntityRepository.php#L138 `EntityRepository#count()` calls `EntityPersister#count()`, which defines itself as `public function count(array|Criteria $criteria = []): int`. This methos has two implementations, `AbstractEntityPersister#count()` and `BasicEntityPersister#count()`, both of which have the same method signature. However, `EntityRepository#count()` is defined as `public function count(array $criteria = []): int`, completely discarding the `Criteria` option. Please add `Criteria` to this parameter to make it match the interface and improve UX. #### Why Because it makes sense. Instead of having to write a custom EntityRepository method, users could write something like this: ```php $newUsersThisMonth = $em->getRepository(User::class)->count( Criteria::expr()->gte('createdAt', new DateTime('midnight first day of this month')) ); ``` #### How ```diff -public function count(array $criteria = []): int +public function count(array|Criteria $criteria = []): int ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7573