D
D
Dos2021-06-09 15:14:14
symfony
Dos, 2021-06-09 15:14:14

How to fix "Given object is not an instance of the class this property was declared in" error?

Hello. I can't figure out why an error occurs when calling the flush()method\Doctrine\ORM\EntityManagerInterface

60c0b072bd7f8528490204.png

<?php

declare(strict_types=1);

namespace App\Shared;

use Doctrine\ORM\EntityManagerInterface;

class Flusher
{
    private EntityManagerInterface $em;
    private EventDispatcher $dispatcher;

    public function __construct(EntityManagerInterface $em, EventDispatcher $dispatcher)
    {
        $this->em = $em;
        $this->dispatcher = $dispatcher;
    }

    public function flush(AggregateRoot ...$roots): void
    {
        dump($roots);
        $this->em->flush();

        foreach ($roots as $root) {
            $this->dispatcher->dispatch($root->releaseEvents());
        }
    }
}


What could be the problem?

Doctrine: v2.8.3
Symfony: v5.2.6

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question