Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ArrayCollection::createFrom. #91

Merged
merged 2 commits into from
Jul 15, 2016
Merged

Conversation

Bilge
Copy link
Contributor

@Bilge Bilge commented Jul 8, 2016

This allows derived classes to specify how new instances should be created when constructor semantics have changed. Without this, derived classes that modify constructor semantics have to re-implement the four affected methods using copy and paste because all hard-coded calls to new static($elements) are invalid.

🔖 I would appreciate a new tag for this PR.

@Ocramius
Copy link
Member

From the IRC logs, here's the "why" behind this PR:

  • consumer may sub-class ArrayCollection
  • sub-class of ArrayCollection may define public function __construct(HahaSomething $else)
  • these methods would crash due to new static() (should use new self() or allow delegations, like done in this PRs)

The issue is that ArrayCollection has been designed A LOT OF TIME AGO, and hasn't been made final. This leads to very fragile subclasses, because the design is not extensible by itself.

We can't make ArrayCollection final though, as it's extensively extended everywhere, and even extended within ORM and ODMs. Therefore we'd break BC after multiple major versions, and with large warning upfront.

The proper solution would be to implement Collection in subclasses, but meanwhile, this patch is an acceptable fix. Tests representing the scenario described above are still required here though.

@Ocramius Ocramius added the Bug label Jul 11, 2016
@Ocramius Ocramius added this to the 1.4.0 milestone Jul 11, 2016
@Ocramius Ocramius self-assigned this Jul 11, 2016
@Bilge Bilge force-pushed the create-from branch 2 times, most recently from 131df33 to d451640 Compare July 13, 2016 15:34
@Bilge
Copy link
Contributor Author

Bilge commented Jul 13, 2016

@Ocramius Test added. I also got rid of that shitty bootstrap.

@Ocramius
Copy link
Member

👍 thanks!

@Ocramius Ocramius merged commit a58af3f into doctrine:master Jul 15, 2016
@Bilge Bilge deleted the create-from branch December 30, 2023 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants