-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Description
I found a severe pitfall in this example code:
symfony-docs/event_dispatcher.rst
Lines 198 to 208 in b9f8400
| :class:`Symfony\\Component\\EventDispatcher\\Attribute\\AsEventListener` | |
| can also be applied to methods directly:: | |
| namespace App\EventListener; | |
| use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | |
| final class MyMultiListener | |
| { | |
| #[AsEventListener] | |
| public function onCustomEvent(CustomEvent $event): void |
There seems to be an implicit assumption here that class CustomEvent has been defined and exists in the same namespace.
If CustomEvent is defined in the App\Event namespace used by other examples in this file then the AsEventListener attribute fails silently and the listener method will never do anything.
Specifically, there is a missing use statement here and it's not easy to debug.
Metadata
Metadata
Assignees
Labels
No labels