DDC-238: PersistentCollection is not initialized when toArray() is called #297

Closed
opened 2026-01-22 12:33:47 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 5, 2010).

Jira issue originally created by user nicokaiser:

When receiving entities from the database, collections are received as PersistentCollection objects.

A PersistentCollectionmay not be initialized (i.e. its elements are not loaded), this is done via "_initialize()" when the elements are accessed for the first time (i.e. forAll() or the corresponding "foreach" call).

However when toArray() is called, the _initialize() call is missing, so the method may return an empty array even if the collection has elements.

Shouldn't PersistentCollection::toArray() look like this?

    public function toArray()
    {
        $this->_initialize();
        return $this->_coll->toArray();
    }
Originally created by @doctrinebot on GitHub (Jan 5, 2010). Jira issue originally created by user nicokaiser: When receiving entities from the database, collections are received as PersistentCollection objects. A PersistentCollectionmay not be initialized (i.e. its elements are not loaded), this is done via "_initialize()" when the elements are accessed for the first time (i.e. forAll() or the corresponding "foreach" call). However when toArray() is called, the _initialize() call is missing, so the method may return an empty array even if the collection has elements. Shouldn't PersistentCollection::toArray() look like this? ``` public function toArray() { $this->_initialize(); return $this->_coll->toArray(); } ```
admin added the Bug label 2026-01-22 12:33:47 +01:00
admin closed this issue 2026-01-22 12:33:47 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

@doctrinebot commented on GitHub (Jan 5, 2010): - duplicates [DDC-216: PersistentCollection#toArray() should call _initialize()](http://www.doctrine-project.org/jira/browse/DDC-216)
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

Comment created by romanb:

Right, we got this reported two times already (this is the third) so I guess I better go fix this now ;)

@doctrinebot commented on GitHub (Jan 5, 2010): Comment created by romanb: Right, we got this reported two times already (this is the third) so I guess I better go fix this now ;)
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

Comment created by romanb:

Should be fixed now.

@doctrinebot commented on GitHub (Jan 5, 2010): Comment created by romanb: Should be fixed now.
Author
Owner

@doctrinebot commented on GitHub (Jan 5, 2010):

Issue was closed with resolution "Fixed"

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

No dependencies set.

Reference: doctrine/archived-orm#297