[PR #9001] Remove Proxy from EntityManagerInterface contract #11306

Open
opened 2026-01-22 16:10:20 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/9001

State: closed
Merged: Yes


After merging #8922 by @simPod, I had a deeper look that the implementation to see if we can fix some of the newly baselined errors. I'd like to partially revert the change now. Sorry for the confusion.

#8922 added an intersection with the Proxy interface to the return type of EntityManagerInterface::getReference() and getPartialReference(). Here's why I now think that this is problematic:

  1. While our implementation EntityManager might return such an object, we cannot guarantee that it will. If you look at the following code snippet, you can see that the actual entity is returned instead of a reference, if the entity has already been registered with the UoW. In that case, the returned entity might not be a proxy object.

    04d28a9362/lib/Doctrine/ORM/EntityManager.php (L515-L520)

    If we kept the Proxy interface in the return type, the correct type would be (T&Proxy)|T|null.

  2. The Proxy interface is somewhat an implementation detail of our EntityManager implementation that should not be leaked to the interface. I believe, the ORM should be able to move to a different proxy library without violating the contract of EntityManagerInterface.

**Original Pull Request:** https://github.com/doctrine/orm/pull/9001 **State:** closed **Merged:** Yes --- After merging #8922 by @simPod, I had a deeper look that the implementation to see if we can fix some of the newly baselined errors. I'd like to partially revert the change now. Sorry for the confusion. #8922 added an intersection with the `Proxy` interface to the return type of `EntityManagerInterface::getReference()` and `getPartialReference()`. Here's why I now think that this is problematic: 1. While our implementation `EntityManager` _might_ return such an object, we cannot guarantee that it will. If you look at the following code snippet, you can see that the actual entity is returned instead of a reference, if the entity has already been registered with the UoW. In that case, the returned entity might not be a proxy object. https://github.com/doctrine/orm/blob/04d28a93628157e7174f4322a1b1cbdbf60afe12/lib/Doctrine/ORM/EntityManager.php#L515-L520 If we kept the `Proxy` interface in the return type, the correct type would be `(T&Proxy)|T|null`. 2. The `Proxy` interface is somewhat an implementation detail of our `EntityManager` implementation that should not be leaked to the interface. I believe, the ORM _should_ be able to move to a different proxy library without violating the contract of `EntityManagerInterface`.
admin added the pull-request label 2026-01-22 16:10: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#11306