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

Breaking change and Exception: Collection->groupBy() with callable in the form [$object, 'method'] #32470

Closed
LMCom opened this issue Apr 21, 2020 · 2 comments
Labels

Comments

@LMCom
Copy link

LMCom commented Apr 21, 2020

  • Laravel Version: 7.6.2
  • PHP Version: 7.3.17
  • Database Driver & Version:

Description:

A breaking change was introduced with version 5.5. It is still there.
To allow multi level grouping, it is checked, if $groupBy is an array.

See
https://github.com/laravel/framework/blob/7.x/src/Illuminate/Support/Collection.php#L431

Introduced:
4fb6206#diff-1f18a78060929ba4f93e96a4d21d022dR657

If $groupBy is an array, the multi level code path is used. However, $groupBy can be a callable, and a callable can be in the form [$object, 'method']. In this case, it should be treated like other callables that are passed to $this->valueRetriever() a few lines later. This was the behaviour before this change.

This is not only a breaking change, but also a bug, because it leads to an exception in data_get() in helpers.php: "explode() expects parameter 2 to be string, object given".

Steps To Reproduce:

Call the method accordingly.

@patriziotomato
Copy link
Contributor

Some of the rare reasons to hate PHP :-(
https://stackoverflow.com/questions/32459408/php-callable-method-not-as-array

patriziotomato referenced this issue Apr 21, 2020
…to groupBy an array, each element applies for an level in the returned collection.
@driesvints driesvints added the bug label Apr 21, 2020
@driesvints
Copy link
Member

I sent in a PR for this: #32471

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

No branches or pull requests

3 participants