Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\Common;

use function spl_object_hash;
use function spl_object_id;

/**
* The EventManager is the central point of Doctrine's event listener system.
Expand Down Expand Up @@ -81,12 +81,12 @@ public function hasListeners(string $event): bool
public function addEventListener(string|array $events, object $listener): void
{
// Picks the hash code related to that listener
$hash = spl_object_hash($listener);
$oid = spl_object_id($listener);

foreach ((array) $events as $event) {
// Overrides listener if a previous one was associated already
// Prevents duplicate listeners on same event (same instance only)
$this->listeners[$event][$hash] = $listener;
$this->listeners[$event][$oid] = $listener;
}
}

Expand All @@ -98,10 +98,10 @@ public function addEventListener(string|array $events, object $listener): void
public function removeEventListener(string|array $events, object $listener): void
{
// Picks the hash code related to that listener
$hash = spl_object_hash($listener);
$oid = spl_object_id($listener);

foreach ((array) $events as $event) {
unset($this->listeners[$event][$hash]);
unset($this->listeners[$event][$oid]);
}
}

Expand Down