[11.x] Preserve item type (array or object) when using Arr::select() or Collection::select() #50749
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.
10.44.0 added the
Collection::select()
andArr::select()
methods #49845 and 10.45.0 updated it to work with ArrayAccess #50072However, these convert any item in either an array or the Collection into an array even if it is an object. See https://github.com/laravel/framework/blob/11.x/src/Illuminate/Collections/Arr.php#L532-L533
For example, if you have an array of objects and select a single column, it will become an array of arrays.
This is unexpected behavior as the Collection returned from Query Builder has each row of data represented as a
stdClass
object. Usingselect
on that Collection then converts all thestdClass
objects toarray
types, breaking downstream code.The proposed change would coerce the individual value of the Collection or Array back into an
object
if the value was originally an object.