[EventDispathcer] Fix removeListener

This commit is contained in:
Victor 2013-02-08 14:08:13 +01:00 committed by Fabien Potencier
parent 8c250bd9c5
commit 87f3db780e
2 changed files with 23 additions and 1 deletions

View File

@ -100,7 +100,7 @@ class EventDispatcher implements EventDispatcherInterface
}
foreach ($this->listeners[$eventName] as $priority => $listeners) {
if (false !== ($key = array_search($listener, $listeners))) {
if (false !== ($key = array_search($listener, $listeners, true))) {
unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
}
}

View File

@ -207,6 +207,28 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
}
/**
* @see https://bugs.php.net/bug.php?id=62976
*
* This bug affects:
* - The PHP 5.3 branch for versions < 5.3.18
* - The PHP 5.4 branch for versions < 5.4.8
* - The PHP 5.5 branch is not affected
*/
public function testWorkaroundForPhpBug62976()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener('bug.62976', new CallableClass());
$dispatcher->removeListener('bug.62976', function() {});
}
}
class CallableClass
{
public function __invoke()
{
}
}
class TestEventListener