DDC-251: ArrayCollection::__construct() must be an array, object given #3232

Closed
doctrinebot opened this Issue Jan 13, 2010 · 6 comments

1 participant

@doctrinebot

Jira issue originally created by user bjori:

Running index.php in the Doctrine2 sandbox results in a fatal error:
PHP Catchable fatal error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::**construct() must be an array, object given, called in /home/bjori/doctrine2/lib/Doctrine/ORM/UnitOfWork.php on line 468 and defined in /home/bjori/doctrine2/lib/Doctrine/Common/Collections/ArrayCollection.php on line 53

Unsure what exactly is going on, but this is the smallest reproduce case I have managed to create.

@doctrinebot

Comment created by romanb:

I think I've found the issue. Its a bug in the lazy-load code of OneToOneMapping (which is also used for ManyToOne).

I am going to fix it.

Note, however, that self-referencing association + inheritance on a base type is currently a very bad combination because it basically causes the whole object tree to be loaded (the whole table). Say we have a standard parent-child (one-to-many) without inheritance. Each object has 1 parent and many children. When you query for any object (without joining anything) the children field is set to an empty collection and the parent field is set to a proxy object, so only 1 database query as expected.

Now comes inheritance into the game. More specifically, if the targetEntity of the "parent" field is not an outermost subtype. That causes Doctrine to not be able to use a proxy as the parent, because the proxy might have the wrong type! So it is forced to load the object.

@doctrinebot

Comment created by romanb:

I'll make this clear in an example.

The following is unproblematic:

class Category {
   private $parentCategory;
   private $childCategories;
}

The following is also unproblematic, where the parent always is an outermost subtype:

class Category {
   private $parentCategory; // targetEntity="SpecialCategory"
   private $childCategories;
}
class SpecialCategory extends Category {
}

The following however is problematic:

class Category {
   private $parentCategory; // targetEntity="Category"
   private $childCategories;
}
class SpecialCategory extends Category {
}
class AnotherSpecialCategory extends Category {
}

Doctrine cant put a CategoryProxy into "parent", because "parent" might be a subtype (SpecialCategory or AnotherSpecialCategory) thus it does not know which proxy to use.

To better solve this it would require transparently joining at least the discriminator column of the parent entity but that is a quite tricky.

@doctrinebot

Comment created by romanb:

Should be fixed now.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by bjori:

Thanks for the explanation, and the fix! :D

@doctrinebot doctrinebot added this to the 2.0-ALPHA4 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment