DDC-1034: Registered lifecycle callbacks of derived classes have unexpected call sequence #1291

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

Originally created by @doctrinebot on GitHub (Feb 15, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user bart:

Situation:
Create an abstract base class (@InheritanceType("JOINED")) and a derived class, both having the annotation @HasLifecycleCallbacks and both having a method with annotation @PostLoad (different method names). The sequence of methods being called when an object is loaded from the database is not as expected.

Expected output:
Called Che\Tmp\BaseClass::PostLoadBase
Called Che\Tmp\DerivedClass::PostLoadDerived
(base value, derived value)

Actual output:
Called Che\Tmp\BaseClass::PostLoadBase
Called Che\Tmp\DerivedClass::PostLoadDerived
Called Che\Tmp\BaseClass::PostLoadBase
(base value)

Test code:
See attachment for classes

// Assume there is an entity manager $em
// Create object
$newDerived = new \Che\Tmp\DerivedClass();
$em->persist($newDerived);

// Fetch object
$derived = $em->findById('\Che\Tmp\DerivedClass', 1);
$derived->echoList();

Possible problem cause

ClassMetadataInfo::addLifecycleCallback($callback, $event) method has a note 'If the same callback is registered more than once, the old one will be overridden'. We are not sure whether this is the case.

Originally created by @doctrinebot on GitHub (Feb 15, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user bart: Situation: Create an abstract base class (@InheritanceType("JOINED")) and a derived class, both having the annotation @HasLifecycleCallbacks and both having a method with annotation @PostLoad (different method names). The sequence of methods being called when an object is loaded from the database is not as expected. Expected output: Called Che\Tmp\BaseClass::PostLoadBase Called Che\Tmp\DerivedClass::PostLoadDerived (base value, derived value) Actual output: Called Che\Tmp\BaseClass::PostLoadBase Called Che\Tmp\DerivedClass::PostLoadDerived Called Che\Tmp\BaseClass::PostLoadBase (base value) Test code: See attachment for classes // Assume there is an entity manager $em // Create object $newDerived = new \Che\Tmp\DerivedClass(); $em->persist($newDerived); // Fetch object $derived = $em->findById('\Che\Tmp\DerivedClass', 1); $derived->echoList(); Possible problem cause ClassMetadataInfo::addLifecycleCallback($callback, $event) method has a note 'If the same callback is registered more than once, the old one will be overridden'. We are not sure whether this is the case.
admin added the Bug label 2026-01-22 13:08:33 +01:00
admin closed this issue 2026-01-22 13:08:35 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2011):

Comment created by @beberlei:

Fixed.

@doctrinebot commented on GitHub (Mar 4, 2011): Comment created by @beberlei: Fixed.
Author
Owner

@doctrinebot commented on GitHub (Mar 4, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Mar 4, 2011): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/73ee018a6104b0106503

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/73ee018a6104b0106503 - [10940_TestClasses.php](https://gist.github.com/73ee018a6104b0106503#file-10940_TestClasses-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1291