This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
Prevent DataTransferObjectCollection from iterating over array copy #166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the introduction of 2.8.0 (88ffe87) the
DataTransferObjectCollection
iterates over copy of the internal$collection
array instead of over the current value of array itself.This breaks backwards compatibility as demonstrated by the testcase below. Before 2.8.0, this test would pass and on 2.8.0 it fails.
This PR is the simplest solution to make the above test pass, but also breaks backwards compatibility as it changes the type of the protected
$collection
field.I think it is a design decision on which type of backwards compatibility to break, so I'm wondering about your opinion on this.
From one perspective it also makes some sense to have the collections Immutable (implicit), while on the other hand the current API is explicit about immutability for DTO's (non collections) already.
There are multiple ways to re-introduce the behavior described above, other that the proposed code:
protected array $collection = [];
and create a newArrayIterator
every time theoffsetSet
method is called (prone to side-effects, resetting the iterator position)DataTransferObjectAssociativeCollection
, removing theArrayIterator
fromDataTransferObjectCollection
, that class would probably also need # 2.