Skip to content

Conversation

@tm1000
Copy link
Contributor

@tm1000 tm1000 commented Jan 20, 2021

This fixes #35947. Since collections can deal with objects then the method sortByMany taken from Arr should be able to deal with objects as well

This fixes laravel#35947. Since collections can deal with objects then the method sortByMany taken from Arr should be able to deal with objects as well
@tm1000 tm1000 changed the title Fixes #35947 [8.x] Fixes #35947 use data_get over Arr::get in Collection Jan 20, 2021
@GrahamCampbell
Copy link
Collaborator

I wouldn't say this is a bug, but by design? Collections are intended to wrap arrays, not objects.

@tm1000
Copy link
Contributor Author

tm1000 commented Jan 20, 2021

@GrahamCampbell please see my description in #35947. If that was the case then why does every result from Illuminate return a collection (that has stdClass elements... the reasoning here is because of the usage of PDO::FETCH_OBJ)

Furthermore I'm being told over there by @derekmd that Collections DOES support dealing with Objects through it's usage of the data_get function.

So someone is confused as to how this is supposed to work. Either the documentation needs to be updated to state that Collections shouldn't be used against illuminate responses (which boy that would be a big change since illuminate responses return collections as wrapped stdClass responses because of PDO::FETCH_OBJ) or this function should throw an error instead of silently pretending it sorted... when it just did nothing.

@redbastie
Copy link

@GrahamCampbell please see my description in #35947. If that was the case then why does every result from Illuminate return a collection (that has stdClass elements... the reasoning here is because of the usage of PDO::FETCH_OBJ)

Because an array can contain an object as a value?

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.

Collection sortBy does not work if collection elements are stdClass

4 participants