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

Mark Selectable::matching as a mutation free #124

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

fluffycondor
Copy link
Contributor

@orklah
Copy link
Collaborator

orklah commented Aug 11, 2022

Note: I don't know Doctrine enough so I may ask stupid questions :)

Is the creation of a new Collection necessarily mutable-free (if so, should Collection::__construct be flagged as mutation-free)? Does it clone the provided Collection maybe?

@fluffycondor
Copy link
Contributor Author

Is the creation of a new Collection necessarily mutable-free (if so, should Collection::__construct be flagged as mutation-free)?
Does it clone the provided Collection maybe?

Collection interface doesn't specify any requirements for realizations' constructor. The only implementation Doctrine has is ArrayCollection, which takes an array. It doesn't clone deeply array values, so if it's an array of objects, objects will be copied by ref.
So, Selectable::matching will definitely return a new Collection, but if the values are not scalar, it will be copied by ref. As far as I understand, it's still can be called mutation-free.

@ygottschalk
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants