[PR #6755] EntityManager::getReference() can return null #10122

Closed
opened 2026-01-22 16:06:30 +01:00 by admin · 0 comments
Owner

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

State: closed
Merged: Yes


When the requested class has subclasses, a proxy cannot be returned, and the entity has to be loaded from the DB to figure out its actual class:

13f838f8be/lib/Doctrine/ORM/EntityManager.php (L498-L500)

Because find() is used, if the entity doesn't exist, EntityManager::getReference() therefore returns null.

I think that either:

  • the return type of EntityManagerInterface::getReference() should be object|null
  • or EntityManager::getReference() should throw an ORMException when the id doesn't exist

This is a PR for the first proposal, but if you prefer the second approach (BC break?) I can change the PR.

**Original Pull Request:** https://github.com/doctrine/orm/pull/6755 **State:** closed **Merged:** Yes --- When the requested class has subclasses, a proxy cannot be returned, and the entity has to be loaded from the DB to figure out its actual class: https://github.com/doctrine/doctrine2/blob/13f838f8bed021cc67e564ec1ff6e994a1a499a8/lib/Doctrine/ORM/EntityManager.php#L498-L500 Because `find()` is used, if the entity doesn't exist, `EntityManager::getReference()` therefore returns `null`. I think that either: - the return type of `EntityManagerInterface::getReference()` should be `object|null` - or `EntityManager::getReference()` should throw an `ORMException` when the id doesn't exist This is a PR for the first proposal, but if you prefer the second approach (BC break?) I can change the PR.
admin added the pull-request label 2026-01-22 16:06:30 +01:00
admin closed this issue 2026-01-22 16:06:30 +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#10122