Hi Greg, The wording is a bit unfortunate, let me clarify (and then maybe you can edit the tutorial https://github.com/doctrine/doctrine2/blob/master/docs/en/tutorials/getting-started.rst, if you find better wording?).
Usually, collections in PHP are represented by plain old arrays: these are useless for Doctrine, because we can't intercept things such as "an array key was read" or "an array key was written". Therefore, we have a Doctrine\Common\Collections\Collection interface ( https://github.com/doctrine/collections/blob/315485ae4bc22affb75be25709740949460b851a/lib/Doctrine/Common/Collections/Collection.php ) to the rescue. A collection is an array-alike structure that has an object-oriented interface. By implementing collections within the ORM, we can intercept access to the collection values, and therefore do some of the ORM trickery that happens when you try to load association records. In your logic, you instantiate an ArrayCollection ( https://github.com/doctrine/collections/blob/315485ae4bc22affb75be25709740949460b851a/lib/Doctrine/Common/Collections/ArrayCollection.php ), which is just the simplest implementation of ArrayCollection. When the ORM saves/loads your objects, it replaces your ArrayCollection with a PersistentCollection ( https://github.com/doctrine/doctrine2/blob/44feacd32764207e2394d9f42e1de57f3571b79d/lib/Doctrine/ORM/PersistentCollection.php ), which contains a few interesting things about "initializing" (lazy loading) and diff-computation (for committing changes to a DB). Both ArrayCollection and PersistentCollection are implementations of the Collection interface, but if you dump your entities (do it only if you have xdebug installed!), then you will see that there is a bit of magic going on internally. Hope that clarifies it. Please remember to edit the text on the documentation, if this was helpful and you now understand what is going on :-) Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 12 July 2016 at 02:20, Greg Bell <[email protected]> wrote: > Hi All, > > Looking for a little clarification. The official tutorial > <http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html#adding-bug-and-user-entities> > says: > > "Whenever an entity is recreated from the database, an Collection > implementation of the type Doctrine is injected into your entity instead of > an array. Compared to the ArrayCollection this implementation helps the > Doctrine ORM understand the changes that have happened to the collection > which are noteworthy for persistence." > > "an Collection implementation of the type Doctrine is injected into your > entity instead of an array"? Does this mean to say an ArrayCollection is > injected? > > This is right after we've used two ArrayCollection to hold the > reportedBugs and assignedBugs in the User. > > Then "Compared to the ArrayCollection..." but the code *is* using an > ArrayCollection. > > Just trying to understand. > > Many thanks. > > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
