merged branch vicb/event (PR #7023)
This PR was squashed before being merged into the 2.0 branch (closes #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 !
This commit is contained in:
commit
ade5de0da1
@ -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