DDC-2303: @param wrong in Doctrine\ORM\PersistentCollection::__constructor Edit #2893

Closed
opened 2026-01-22 14:06:48 +01:00 by admin · 7 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 18, 2013).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user datkind:

When i try to generate a new PersistentCollection like this:

 $collection = new ArrayCollection();
 new \Doctrine\ORM\PersistentCollection(
            $this->getEntityManager(),
            new ClassMetadata(''),
             $collection
        );

i get an typ hinting error like
"Expected array, got "Doctrine\Common\Collections\ArrayCollection"

This could be fixed by changing the type hinting for the Doctrine\ORM\PersistentCollection::*constructor
*From:

 /****
 * Creates a new persistent collection.
 *
 * @param EntityManager $em    The EntityManager the collection will be associated with.
 * @param ClassMetadata $class The class descriptor of the entity type of this collection.
 * @param array       $coll  The collection elements.
 */
public function **construct(EntityManager $em, $class, $coll)
{

To:

 /****
 * Creates a new persistent collection.
 *
 * @param EntityManager $em    The EntityManager the collection will be associated with.
 * @param ClassMetadata $class The class descriptor of the entity type of this collection.
 * @param \ArrayAccess $coll  The collection elements.
 */
public function **construct(EntityManager $em, $class, $coll)
{
Originally created by @doctrinebot on GitHub (Feb 18, 2013). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user datkind: When i try to generate a new PersistentCollection like this: ###### ``` $collection = new ArrayCollection(); new \Doctrine\ORM\PersistentCollection( $this->getEntityManager(), new ClassMetadata(''), $collection ); ``` ###### i get an typ hinting error like **"Expected array, got "Doctrine\Common\Collections\ArrayCollection"** This could be fixed by changing the type hinting for the Doctrine\ORM\PersistentCollection::*_constructor *_From:__ ###### ``` /**** * Creates a new persistent collection. * * @param EntityManager $em The EntityManager the collection will be associated with. * @param ClassMetadata $class The class descriptor of the entity type of this collection. * @param array $coll The collection elements. */ public function **construct(EntityManager $em, $class, $coll) { ``` ###### ######################################### __To:__ ###### ``` /**** * Creates a new persistent collection. * * @param EntityManager $em The EntityManager the collection will be associated with. * @param ClassMetadata $class The class descriptor of the entity type of this collection. * @param \ArrayAccess $coll The collection elements. */ public function **construct(EntityManager $em, $class, $coll) { ``` ######
admin added the Bug label 2026-01-22 14:06:48 +01:00
admin closed this issue 2026-01-22 14:06:48 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 18, 2013):

Comment created by datkind:

When i try to generate a new PersistentCollection like this:


     $collection = new ArrayCollection();
     new \Doctrine\ORM\PersistentCollection(
                $this->getEntityManager(),
                new ClassMetadata(''),
                 $collection
            );

I get an typ hinting error like
"Expected array, got "Doctrine\Common\Collections\ArrayCollection"

This could be fixed by changing the type hinting for the Doctrine\ORM\PersistentCollection::*constructor
*From:

     /****
     * Creates a new persistent collection.
     *
     * @param EntityManager $em    The EntityManager the collection will be associated with.
     * @param ClassMetadata $class The class descriptor of the entity type of this collection.
     * @param array       $coll  The collection elements.
     */
    public function **construct(EntityManager $em, $class, $coll)
    {

To:

     /****
     * Creates a new persistent collection.
     *
     * @param EntityManager $em    The EntityManager the collection will be associated with.
     * @param ClassMetadata $class The class descriptor of the entity type of this collection.
     * @param \ArrayAccess $coll  The collection elements.
     */
    public function **construct(EntityManager $em, $class, $coll)
    {

@doctrinebot commented on GitHub (Feb 18, 2013): Comment created by datkind: When i try to generate a new PersistentCollection like this: ``` $collection = new ArrayCollection(); new \Doctrine\ORM\PersistentCollection( $this->getEntityManager(), new ClassMetadata(''), $collection ); ``` I get an typ hinting error like **"Expected array, got "Doctrine\Common\Collections\ArrayCollection"** This could be fixed by changing the type hinting for the Doctrine\ORM\PersistentCollection::*_constructor *_From:__ ``` /**** * Creates a new persistent collection. * * @param EntityManager $em The EntityManager the collection will be associated with. * @param ClassMetadata $class The class descriptor of the entity type of this collection. * @param array $coll The collection elements. */ public function **construct(EntityManager $em, $class, $coll) { ``` __To:__ ``` /**** * Creates a new persistent collection. * * @param EntityManager $em The EntityManager the collection will be associated with. * @param ClassMetadata $class The class descriptor of the entity type of this collection. * @param \ArrayAccess $coll The collection elements. */ public function **construct(EntityManager $em, $class, $coll) { ```
Author
Owner

@doctrinebot commented on GitHub (Feb 18, 2013):

Comment created by stof:

There is no typehint in the PersistentCollection constructor. So the issue cannot come from this place (the phpdoc is wrong btw, it expects a Collection, not an array)

Please give the full error, i.e. the message and the location so that we can know where it happens.

@doctrinebot commented on GitHub (Feb 18, 2013): Comment created by stof: There is no typehint in the PersistentCollection constructor. So the issue cannot come from this place (the phpdoc is wrong btw, it expects a Collection, not an array) Please give the full error, i.e. the message **and the location** so that we can know where it happens.
Author
Owner

@doctrinebot commented on GitHub (Feb 20, 2013):

Comment created by datkind:

There error is not in the function declaration, it is in the @param in the doc block of the constructor.

Using PHPStorm as IDE i got this error thrown by the IDE it self, not php. (Screenshot will be attached)

Using ZF2 the error is on line 121 at:
vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php

@doctrinebot commented on GitHub (Feb 20, 2013): Comment created by datkind: There error is not in the function declaration, it is in the @param in the doc block of the constructor. Using PHPStorm as IDE i got this error thrown by the IDE it self, not php. (Screenshot will be attached) Using ZF2 the error is on line 121 at: vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php
Author
Owner

@doctrinebot commented on GitHub (Feb 20, 2013):

Comment created by datkind:

Using PHPStorm as IDE i got "Expected array, got "Doctrine\Common\Collections\ArrayCollection" thrown by the IDE it self, not php.

@doctrinebot commented on GitHub (Feb 20, 2013): Comment created by datkind: Using PHPStorm as IDE i got "Expected array, got "Doctrine\Common\Collections\ArrayCollection" thrown by the IDE it self, not php.
Author
Owner

@doctrinebot commented on GitHub (Feb 20, 2013):

Comment created by datkind:

Using PHPStorm as IDE i got "Expected array, got "Doctrine\Common\Collections\ArrayCollection" thrown by the IDE it self, not php.

@doctrinebot commented on GitHub (Feb 20, 2013): Comment created by datkind: Using PHPStorm as IDE i got "Expected array, got "Doctrine\Common\Collections\ArrayCollection" thrown by the IDE it self, not php.
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2013):

Comment created by @ocramius:

The correct type hint here is Doctrine\Common\Collections\Collection.

I'm closing this as invalid, since you shouldn't instantiate a persistent collection on your own. Consider opening a pull request at https://github.com/doctrine/doctrine2 instead if you want to fix the typehint.

@doctrinebot commented on GitHub (Feb 26, 2013): Comment created by @ocramius: The correct type hint here is `Doctrine\Common\Collections\Collection`. I'm closing this as invalid, since you shouldn't instantiate a persistent collection on your own. Consider opening a pull request at https://github.com/doctrine/doctrine2 instead if you want to fix the typehint.
Author
Owner

@doctrinebot commented on GitHub (Feb 26, 2013):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Feb 26, 2013): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2893