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

[DI][EventDispatcher] Undocumented BC Break in RegisterListenersPass #36708

Copy link
Copy link
Closed
@bestform

Description

@bestform
Issue body actions

Symfony version(s) affected: all from 3.2.0

Description
#20953 changed the way event subscribers are written to the container at compile time. Before this change it wrote calls to addSubscriberService to the container. Now it resolves the listeners and writes calls to addListener.
Logic in getSubscribedEvents that depends on the current state at runtime will no longer be called on every run. It will be executed only once at compile time.

To make it obvious how this can break existing code is an EventSubscriber that listens to userRegistered events and wants to send an e-mail, when a user registered at night. It achieves this by returning the events it wants to listen to depending on the time, so it only will register for the event if it is past 10pm and before 8am.
After the update, the subscriber will either always send an e-mail or never, depending on the time the container was compiled at.

While this is a very constructed example I think it makes obvious why this is kind of serious, as it will change how the code behaves depending on seemingly arbitrary things.

How to reproduce
Create an EventSubscriber that has runtime dependent logic inside getSubscribedEvents. It will only run this logic at compile time and the events will not be handled depending on that logic at runtime anymore.

Possible Solution
As this change is from 2017 I don't think documenting the bc break in a changelog makes much sense at this time. But I think it should be documented in the interface doc block of the getSubscribedEvents that classes implementing this method must not depend on runtime state in their implementation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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