Skip to content

EventDispatcher Optional Arguments #21000

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

Open
miqrogroove opened this issue May 25, 2025 · 0 comments
Open

EventDispatcher Optional Arguments #21000

miqrogroove opened this issue May 25, 2025 · 0 comments

Comments

@miqrogroove
Copy link
Contributor

miqrogroove commented May 25, 2025

The :method:`Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch`
method notifies all listeners of the given event. It takes two arguments:
the ``Event`` instance to pass to each listener of that event and the name
of the event to dispatch::
use Acme\Store\Event\OrderPlacedEvent;
use Acme\Store\Order;
// the order is somehow created or retrieved
$order = new Order();
// ...
// creates the OrderPlacedEvent and dispatches it
$event = new OrderPlacedEvent($order);
$dispatcher->dispatch($event);

This article specifies "the name of the event to dispatch" as an argument to the dispatch method, immediately followed by an example that never uses said argument.

There's no explanation I can find about why this argument is optional and what difference it makes if we can have an example without it. Granted there's a note below this block that says OrderPlacedEvent listeners will receive the OrderPlacedEvent. But that would seem to be self-evident and unrelated to the name of the event.

This needs to be clarified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant