8000 Argument 1 passed to "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" must be an instance of Symfony\Component\EventDispatcher\Event, MyBundle\Event\QbCartLoadEvent given. · Issue #32189 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Argument 1 passed to "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" must be an instance of Symfony\Component\EventDispatcher\Event, MyBundle\Event\QbCartLoadEvent given. #32189
Closed
@cronk1986

Description

@cronk1986

Symfony version(s) affected: 4.3.1

Description
I have an exception when I try to dispatch an event from event dispatcher service, the current exception is:

Argument 1 passed to "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" must be an instance of Symfony\Component\EventDispatcher\Event, MyBundle\Event\MyEvent given.

PhpStorm shows "Symfony\Component\EventDispatcher\Event" as deprecated and suggest to use "Symfony\Contracts\EventDispatcher\Event" class but throw the previous exception.

My event class

<php
use Symfony\Contracts\EventDispatcher\Event;

class MyEvent extends Event
{
   //my custom code
}

How to reproduce
Follow the steps below in order to reproduce the exception:

//this code is in a controller class
$this->get('event_dispatcher')->dispatch('myevent', new MyEvent(/*constructor parameters if proceed*/));

If inheritance if changed for "Symfony\Component\EventDispatcher\Event" instead of "Symfony\Contracts\EventDispatcher\Event" works like charm.

I'm not sure if is really a bug or is my code.

Any idea?
Thank you! in advance.

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

      0