Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ade5de0

Browse files
committed
merged branch vicb/event (PR symfony#7023)
This PR was squashed before being merged into the 2.0 branch (closes symfony#7023). Commits ------- 87f3db7 [EventDispathcer] Fix removeListener Discussion ---------- [EventDispathcer] Fix removeListener | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Todo - [x] Add a UT I won't have time to add a test before next Friday but this PR could save some debugging (especially with Silex & Closures) --------------------------------------------------------------------------- by vicb at 2013-02-09T23:32:51Z Probably related to https://bugs.php.net/bug.php?id=62976, I need to do some more investigation - I use 546. anyway the fix is valid for whatever php version. --------------------------------------------------------------------------- by vicb at 2013-02-10T10:24:46Z This **is** related to the PHP bug mentioned above, see http://3v4l.org/Q6WKj: ``` Output for 5.3.18 - 5.3.21, 5.4.8 - 5.5.0alpha4 bool(false) Output for 5.3.0 - 5.3.17, 5.4.0 - 5.4.7 Notice: Object of class Klass could not be converted to int in /in/Q6WKj on line 9 Notice: Object of class Closure could not be converted to int in /in/Q6WKj on line 9 int(0) ``` @fabpot anything more needed to merge this ? --------------------------------------------------------------------------- by fabpot at 2013-02-10T10:26:52Z Is it possible to add a test? --------------------------------------------------------------------------- by vicb at 2013-02-10T10:29:34Z It is, for php versions < fixed version, I'll do that --------------------------------------------------------------------------- by vicb at 2013-02-10T10:42:01Z @fabpot ready Sir ! --------------------------------------------------------------------------- by vicb at 2013-02-10T10:44:35Z well I can probably add an assert, please wait !
2 parents 8c250bd + 87f3db7 commit ade5de0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines 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

Lines 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)