-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Compiled container calls EventDispatcherInterface::addListener()
with non-callable listener
#42283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I am not sure if I really got all the steps that are required to reproduce this. Can you please create a small example application that allows to debug this? |
Please take a look at following phpsandbox notebook, the interesting change is the The notebook uses Symfony Web Skeleton, which already uses the dependency-injection component and has some EventSubscribers configured. |
Symfony's own implementations don't have the That being said, should we remove |
Yes removing the type declaration on the implementation resolves the issue. But IMHO the interface should not use type declarations that can not be used in the implementations. So removing the type declaration on the interface makes sense to me. |
PR: #42319 |
PR has been rejected, see #42319 (comment) for the reason why. |
Symfony version(s) affected: 5.3.4, 5.2.12
Description
The "Backport Type Fixes" commit added a callable type declaration to the
$listener
parameter ofEventDispatcherInterface::addListener()
. Adding that type declaration to implementations will break when using the dependency-injection container. The reason is that the dependency-injection container will generate code that callsaddListener
with an array as listener where at index 0 an closure is passed that will resolve to the object that should be called and at index 1 the method name that should be called is passed. According to the official documentation an array is only considered callable if at index 0 of the array the instantiated object is passed, it seems like passing a closure there is not considered to be callable.How to reproduce
Add a custom EventDispatcher decorater that uses the
addListener()
method signature from the interface:Or add that native type declaration to the EventDispatcher implementation.
Configure some event subscriber in the service configuration.
After that the dependency-injection container is broken:
Possible Solution
Remove the type declaration from the EventDispatcherInterface again.
Or rework the dependency-injection to call
EventDispatcherInterface::addListener()
in a way that is compatible with that type declaration.Additional context
The generated code for the dependency injection container looks like this:
That seems to not pass the native callable type declaration.
The text was updated successfully, but these errors were encountered: