diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index 6bfd7a01dd38..6fa3065f1128 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -39,6 +39,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve private $wrappedListeners; private $firstCalledEvent; private $id; + private $lastEventId = 0; /** * Constructor. @@ -124,7 +125,7 @@ public function dispatch($eventName, Event $event = null) $event = new Event(); } - $this->id = spl_object_hash($event); + $this->id = $eventId = ++$this->lastEventId; $this->preDispatch($eventName, $event); @@ -139,7 +140,7 @@ public function dispatch($eventName, Event $event = null) $this->dispatcher->dispatch($eventName, $event); // reset the id as another event might have been dispatched during the dispatching of this event - $this->id = spl_object_hash($event); + $this->id = $eventId; unset($this->firstCalledEvent[$eventName]); diff --git a/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php index a5f507cd4eea..b9bc1d7f97e1 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php @@ -159,6 +159,22 @@ public function testDispatchNested() $dispatcher->dispatch('foo'); } + public function testDispatchReusedEventNested() + { + $nestedCall = false; + $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); + $dispatcher->addListener('foo', function (Event $e) use ($dispatcher) { + $dispatcher->dispatch('bar', $e); + }); + $dispatcher->addListener('bar', function (Event $e) use (&$nestedCall) { + $nestedCall = true; + }); + + $this->assertFalse($nestedCall); + $dispatcher->dispatch('foo'); + $this->assertTrue($nestedCall); + } + public function testStopwatchSections() { $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch = new Stopwatch());