Skip to content

ArrayCollection/PersistentCollection Architectural Disagreement #6696

Open
@WyrdNexus

Description

@WyrdNexus

While Doctrine will provide either an ArrayCollection, or a PersistentCollection, depending on the state of the Entity, no common Class or Interface reflects their shared methods.

More specifically, when defining an entity's collection getter, the return type cannot be specified.
Options include:

  • PersistentCollection: in most instances, will not be correct.
  • ArrayCollection: has the same methods as PersistentCollection, but in some instances will be a PersistentCollection.
  • Collection/AbstractLazyCollection: in addition to the problems above, it is missing the "matching" method.

This missing common agreement complicates all code implementing these objects, which otherwise could be clean and simple.

For the sake of clarity, consider the PHP7 return type declaration on the getter for such a method.
Both of the following week result in errors:
pubic method getOneToMany(): ArrayCollection
pubic method getOneToMany(): PersistentCollection
The best alternative is:
pubic method getOneToMany(): Collection
... leaving out the method: matching.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions