Skip to content

Recursive dumping of Doctrine entities can cause an infinite loop #462

@janbarasek

Description

@janbarasek

Version: v2.8.2

Bug Description

Snímek obrazovky 2021-01-26 v 21 54 26

Hi, I haven't been able to create a minimal example of this problem, how to simulate this, so a general description must suffice.

When I load an entity from a Doctrine that contains a collection of other entities internally (such as a OneToMany session) and dump that collection (which has not yet fetched data), the dump function often loops and runs out of time, even if it contains the bare minimum of data.

If I increase the timeout to 10 minutes, for example, the dump function will run out after a few minutes, but I couldn't find out exactly where the problem is.

The problem happens to me across projects and I also solved it during the training, when other people asked me about it.

Steps To Reproduce

The minimal example that triggers an infinite loop looks like this:

/**
 * @var ZakaznikKontaktEmail[]|Collection
 * @ORM\OneToMany(targetEntity="ZakaznikKontakt", mappedBy="zakaznik")
 */
private $emails;

public function __construct()
{
	$this->emails = new ArrayCollection;
}

/**
 * @return ZakaznikKontaktEmail[]
 */
public function getEmails(): array
{
	dump($this->emails); // <-- problem is here
	return $this->emails->toArray();
}

Expected Behavior

I tried to implement something like ttl that could stop recursion, but it didn't work. If you have a better idea, I will be very happy.

Thanks!

cc @matikara

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions