Proxy tries to call destructor of not loaded entities, including removed entities #6173

Closed
opened 2026-01-22 15:28:13 +01:00 by admin · 3 comments
Owner

Originally created by @arnaud-lb on GitHub (Feb 9, 2019).

Originally assigned to: @Ocramius on GitHub.

Bug Report

Q A
BC Break ?
Version 2.6.3

Summary

When an entity defines a destructor, an entity proxy will attempt to call the entity's destructor when it's destroyed.

Current behavior

If the proxy never initialised (it never loaded the actual entity), it will apparently try to load the entity during __destruct.

If the entity had been removed(), we may see some unexpected behaviours or some EntityNotFoundException exceptions.

How to reproduce

  • Get a reference to an entity that has a destructor
  • Remove the entity

I've created a failing test case here: db8cfd9d25

Expected behavior

Should a proxy destructor attempt to load the entity if it's not already loaded ?

Originally created by @arnaud-lb on GitHub (Feb 9, 2019). Originally assigned to: @Ocramius on GitHub. ### Bug Report | Q | A |------------ | ------ | BC Break | ? | Version | 2.6.3 #### Summary When an entity defines a destructor, an entity proxy will attempt to call the entity's destructor when it's destroyed. #### Current behavior If the proxy never initialised (it never loaded the actual entity), it will apparently try to load the entity during `__destruct`. If the entity had been `removed()`, we may see some unexpected behaviours or some EntityNotFoundException exceptions. #### How to reproduce - Get a reference to an entity that has a destructor - Remove the entity I've created a failing test case here: https://github.com/arnaud-lb/doctrine2/commit/db8cfd9d2541a31e03f888920b80cdf2549b9574 #### Expected behavior Should a proxy destructor attempt to load the entity if it's not already loaded ?
admin added the Can't FixQuestion labels 2026-01-22 15:28:13 +01:00
admin closed this issue 2026-01-22 15:28:13 +01:00
Author
Owner

@Ocramius commented on GitHub (Feb 9, 2019):

Yes, it should still call the destructor

@Ocramius commented on GitHub (Feb 9, 2019): Yes, it should still call the destructor
Author
Owner

@arnaud-lb commented on GitHub (Feb 11, 2019):

I'm genuinely interested in hearing the rationale behind this.

Intuitively, I would have though that since the entity is not constructed yet, calling its destructor is not necessary, especially since this requires to construct it just for this purpose.

This would be sad, because apart from this bug, this also defeats the purpose of a lazy loading proxy: Entities with a destructor will always be loaded when its proxy/reference is destroyed.

@arnaud-lb commented on GitHub (Feb 11, 2019): I'm genuinely interested in hearing the rationale behind this. Intuitively, I would have though that since the entity is not constructed yet, calling its destructor is not necessary, especially since this requires to construct it just for this purpose. This would be sad, because apart from this bug, this also defeats the purpose of a lazy loading proxy: Entities with a destructor will always be loaded when its proxy/reference is destroyed.
Author
Owner

@Ocramius commented on GitHub (Feb 11, 2019):

I've detailed this in following pre-existing issues (sorry, different repository, but same reasoning applies):

Entities with a destructor will always be loaded when its proxy/reference is destroyed.

Correct.

@Ocramius commented on GitHub (Feb 11, 2019): I've detailed this in following pre-existing issues (sorry, different repository, but same reasoning applies): * https://github.com/Ocramius/ProxyManager/issues/258 * https://github.com/Ocramius/ProxyManager/issues/262 * https://github.com/Ocramius/ProxyManager/issues/373 > Entities with a destructor will always be loaded when its proxy/reference is destroyed. Correct.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6173