Infinite loop in Doctrine event listener when trying to save additional entity
问题 I want that every time a new Distance entity (from Place_A to Place_B) is saved, the reverse distance (from Place_B to Place_A) gets inserted too into the DB. My problem is the following listener loops infinitely (hence the counter): class Listener { public $count; public function prePersist(LifecycleEventArgs $eventArgs) { if ($this->count > 5) { die(); } $entity = $eventArgs->getEntity(); if ($entity instanceof Distance) { // $this->created = microtime(true) in Distance's constructor echo