Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 87f3db7

Browse filesBrowse files
vicbfabpot
authored andcommitted
[EventDispathcer] Fix removeListener
1 parent 8c250bd commit 87f3db7
Copy full SHA for 87f3db7

File tree

2 files changed

+23
-1
lines changed
Filter options

2 files changed

+23
-1
lines changed

‎src/Symfony/Component/EventDispatcher/EventDispatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/EventDispatcher.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function removeListener($eventName, $listener)
100100
}
101101

102102
foreach ($this->listeners[$eventName] as $priority => $listeners) {
103-
if (false !== ($key = array_search($listener, $listeners))) {
103+
if (false !== ($key = array_search($listener, $listeners, true))) {
104104
unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
105105
}
106106
}

‎tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/EventDispatcher/EventDispatcherTest.php
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,28 @@ public function testRemoveSubscriberWithPriorities()
207207
$this->dispatcher->removeSubscriber($eventSubscriber);
208208
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
209209
}
210+
211+
/**
212+
* @see https://bugs.php.net/bug.php?id=62976
213+
*
214+
* This bug affects:
215+
* - The PHP 5.3 branch for versions < 5.3.18
216+
* - The PHP 5.4 branch for versions < 5.4.8
217+
* - The PHP 5.5 branch is not affected
218+
*/
219+
public function testWorkaroundForPhpBug62976()
220+
{
221+
$dispatcher = new EventDispatcher();
222+
$dispatcher->addListener('bug.62976', new CallableClass());
223+
$dispatcher->removeListener('bug.62976', function() {});
224+
}
225+
}
226+
227+
class CallableClass
228+
{
229+
public function __invoke()
230+
{
231+
}
210232
}
211233

212234
class TestEventListener

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.