Skip to content

[EventDispatcher] Incorrect error reported when arguments to dispatch() are swapped #34676

@rimas-kudelis

Description

@rimas-kudelis

Symfony version(s) affected: 4.4.0

Description
The EventDispatcherInterface currently allows dispatching event by its name only (dispatch($eventName)) or by supplying the event and its name (dispatch($event, $eventName)).
In the second case, when the arguments are swapped, an incorrect error will be returned in some cases. Specifically, it will be incorrect when the event will be a subclass of Symfony\Contracts\EventDispatcher\Event as opposed to a subclass of Symfony\Component\EventDispatcher\Event (the latter has been deprecated since 4.3).

How to reproduce
Attempt to dispatch an event that is a subclass of Symfony\Contracts\EventDispatcher\Event and swap the arguments (provide event name first, its object second).

Possible Solution
The line in

} elseif (\is_string($event) && (null === $eventName || $eventName instanceof Event)) {
should be updated to match both event types.

Additional context
This issue is only valid for the 4.4 branch (and maybe 4.3?). In 5.0, EventDispatcher doesn't contain the code in question.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy