From 606f20b7249f87186ba30361bce49d5d7c31cc39 Mon Sep 17 00:00:00 2001 From: Pieter Jordaan Date: Thu, 12 Dec 2013 12:04:56 +0100 Subject: [PATCH] store $this->id in local $id to avoid errors when this value is changed during execution of preDispatch and postDispatch method --- .../HttpKernel/Debug/TraceableEventDispatcher.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index 6bfd7a01dd38d..f97b66282a61e 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -366,15 +366,16 @@ private function saveInfoInProfile(Profile $profile, $updateChildren) private function preDispatch($eventName, Event $event) { + $id = $this->id; //the value of $this->id can change during execution of this method, so we store it in a local variable // wrap all listeners before they are called - $this->wrappedListeners[$this->id] = new \SplObjectStorage(); + $this->wrappedListeners[$id] = new \SplObjectStorage(); $listeners = $this->dispatcher->getListeners($eventName); foreach ($listeners as $listener) { $this->dispatcher->removeListener($eventName, $listener); $wrapped = $this->wrapListener($eventName, $listener); - $this->wrappedListeners[$this->id][$wrapped] = $listener; + $this->wrappedListeners[$id][$wrapped] = $listener; $this->dispatcher->addListener($eventName, $wrapped); } @@ -431,13 +432,13 @@ private function postDispatch($eventName, Event $event) $this->updateProfiles($token, false); break; } - - foreach ($this->wrappedListeners[$this->id] as $wrapped) { + $id = $this->id; + foreach ($this->wrappedListeners[$id] as $wrapped) { $this->dispatcher->removeListener($eventName, $wrapped); - $this->dispatcher->addListener($eventName, $this->wrappedListeners[$this->id][$wrapped]); + $this->dispatcher->addListener($eventName, $this->wrappedListeners[$id][$wrapped]); } - unset($this->wrappedListeners[$this->id]); + unset($this->wrappedListeners[$id]); } private function wrapListener($eventName, $listener)