symfony: [EventDispatcher] After upgrading to 3.3.0 removeSubscriber() does not work any more.

Q A
Bug report? yes
Feature request? no
BC Break report? yes
RFC? no
Symfony version 3.3.0

In some commands I use this kind of functionality to disable the sending of Emails: $this->getContainer()->get('event_dispatcher')->removeSubscriber($this->getContainer()->get('my_email_subscriber'));

And then I put it back:

$this->getContainer()->get('event_dispatcher')->addSubscriber($this->getContainer()->get('my_email_subscriber'));

After some debugging I found out that the EventDispatcher now holds closures to enhance LazyLoading in the $this->listeners array. So the array_search check does not work anymore in function removeListener.

I’m not sure if this really is a bug or if there is a new way now to achieve this.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@nicolas-grekas we cannot deprecate addSubscriber in favor of compiler passes. The Form component cannot use the compiler pass for instance (but we want to be able to use subscribers there).

Looking at it