With your query, DQL mixes the tables instead of counting rows in each table. The result is an erroneous number of rows. It can't explain why and how, but it always fail when I use more than one COUNT()
function in a query.
To count the right number of rows, you have to use sub-queries:
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery('
SELECT COUNT(U.id) AS users,
(SELECT COUNT(T) FROM ProjectUserBundle:Team T) AS teams,
(SELECT COUNT(P) FROM ProjectUserBundle:Post P) AS posts,
(SELECT COUNT(C) FROM ProjectUserBundle:Comment C) AS comments
FROM ProjectUserBundle:User U
');
$counts = $query->getSingleResult();