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

[5.5] Add operator support to Collection@partition #22352

Closed
wants to merge 13 commits into from

Conversation

JosephSilber
Copy link
Member

Enables this:

[$adults, $minors] = User::all()->partition('age', '>=', 18);

@Dylan-DPC-zz
Copy link

This is a breaking change

@jmarcher
Copy link
Contributor

jmarcher commented Dec 8, 2017

@Dylan-DPC Dude, it is not...

{
$partitions = [new static, new static];

$callback = $this->valueRetriever($callback);
$callback = func_num_args() == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be ===?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not make any difference in this case.
func_num_args() will always return an integer, no real need to typecheck in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically there's no difference indeed, just like 90% of other strict comparison cases out there. The difference here is we'll have an (arguably) better code standard.

@Dylan-DPC-zz
Copy link

Oh yeah it is not breaking. But having a parameter named "key" that takes in a callback as well is misleading

@sisve
Copy link
Contributor

sisve commented Dec 8, 2017

Anyone that has derived from Collection and overridden the partition method will now see php warnings. I believe this indicates that the PR should target 5.6.

PHP Warning: Declaration of CustomCollection::partition($callback) should be compatible with Collection::partition($key, $operator = NULL, $value = NULL)

@taylorotwell taylorotwell changed the base branch from 5.5 to master December 8, 2017 14:28
@taylorotwell
Copy link
Member

Looks good to me. Can you submit to master branch because of what @sisve noted.

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.

9 participants