Is there any difference between these two statements:
$this->getDoctrine()->getEntityManager()->getRepository();
$this->getDoctrine()->getRepository();
Does the difference relate to any OOP concept I am missing out?
Is there any difference between these two statements:
$this->getDoctrine()->getEntityManager()->getRepository();
$this->getDoctrine()->getRepository();
Does the difference relate to any OOP concept I am missing out?
In general, no difference, since
is just a helper for
You can have several entity managers, and then there will be a slight difference in getting a repository from one:
But again, no difference in the result you'll get.
All other things being equal, I'd go with the shortest one.
The result is the same, but if you need the entityManager for more than just getting the repository, it might be handy to store it and then recieve the repository as well as do other operations such as flush:
As said before, if you only need to get the Repository, go with the second statement, which is shorter and as easy to read as the first one.
There is no difference. If you look at the source code of AbstractManagerRegistry.php. You can see this code:
As you can see, when you call getRepository(), it first calls getManager() and then getRepository(). I would suggest using the second one as it gives intellisense in IDEs such as PHPStorm. Hope it helps.