[EventDispathcer] Fix removeListener
This commit is contained in:
parent
8c250bd9c5
commit
87f3db780e
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user