Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2303

@param wrong in Doctrine\ORM\PersistentCollection::__constructor Edit

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:

      Description

      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)
        {
                                                                                                  1. _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)
        {
        ###############################################

        Activity

        Hide
        Torsten Granek added a comment -

        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)
            {
        
        
        Show
        Torsten Granek added a comment - 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) {
        Hide
        Christophe Coevoet added a comment -

        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.

        Show
        Christophe Coevoet added a comment - 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.
        Hide
        Torsten Granek added a comment -

        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

        Show
        Torsten Granek added a comment - 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
        Hide
        Torsten Granek added a comment -

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

        Show
        Torsten Granek added a comment - Using PHPStorm as IDE i got "Expected array, got "Doctrine\Common\Collections\ArrayCollection" thrown by the IDE it self, not php.
        Hide
        Torsten Granek added a comment -

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

        Show
        Torsten Granek added a comment - Using PHPStorm as IDE i got "Expected array, got "Doctrine\Common\Collections\ArrayCollection" thrown by the IDE it self, not php.
        Hide
        Marco Pivetta added a comment -

        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.

        Show
        Marco Pivetta added a comment - 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.

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Torsten Granek
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: