2
votes

I have such listener

use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\Common\Persistence\Event\PreUpdateEventArgs;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Events;

class MachineSubscriber implements EventSubscriber

and method

/**
     * @param PreUpdateEventArgs $args
     */
    public function preUpdate(PreUpdateEventArgs $args)

and Doctrine throw Exception

ContextErrorException: Catchable Fatal Error: Argument 1 passed to Certificate\MachineBundle\Event\MachineSubscriber::preUpdate() must be an instance of Doctrine\Common\Persistence\Event\PreUpdateEventArgs, instance of Doctrine\ORM\Event\PreUpdateEventArgs given,

Its strange becouse I use proper class.

1

1 Answers

4
votes

You're using the wrong namespace/class to typehint the preUpdate() function argument. The correct hierarchy is:

Doctrine\Common\EventArgs
|_ Doctrine\ORM\Event\LifecycleEventArgs
  |_ Doctrine\ORM\Event\PreUpdateEventArgs

Typehint with ...

use Doctrine\Common\EventArgs;

public function preUpdate(EventArgs $args)
{
    // ...

... or ...

use Doctrine\ORM\Event\LifecycleEventArgs;

public function preUpdate(LifecycleEventArgs $args)
{
    // ...

... or ...

use Doctrine\ORM\Event\PreUpdateEventArgs;

public function preUpdate(PreUpdateEventArgs $args)
{
    // ...

... but NOT with:

use Doctrine\Common\Persistence\Event\PreUpdateEventArgs;