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.3] Collection::min() incorrectly excludes 0 when calculating minimum #16821

Merged
merged 2 commits into from
Dec 15, 2016

Conversation

thecrypticace
Copy link
Contributor

This commit: e2d317e introduced a (hopefully unintentional) BC break in min() that causes the following to fail:

collect([0, 1, 2, 3])->min() // returns: 1

This is because filter calls array_filter without a callback which in turn removes all falsy values, not just null ones.

I've also updated the changed code in Collection::max() for consistency.

@taylorotwell taylorotwell merged commit 2463e41 into laravel:5.3 Dec 15, 2016
@thecrypticace
Copy link
Contributor Author

Wow that was fast…

@GrahamCampbell GrahamCampbell changed the title Collection::min() incorrectly excludes 0 when calculating minimum [5.3] Collection::min() incorrectly excludes 0 when calculating minimum Dec 15, 2016
@modmac
Copy link

modmac commented Dec 16, 2016

Is it ok that:

collect([1, null, 3, 4])->min() // returns 1

but:

min([1, null, 3, 4]) // returns null

?

@GrahamCampbell
Copy link
Member

Seems pretty stupid to use maps here when we could have just used a loop and saved ourselves all the bugs, and the performance hit, since php doesn't lazily iterate them - we have to go round again and again, for each map.

@taylorotwell
Copy link
Member

Benchmark results iterating over 1 million items using foreach, map with closure, map with named function, etc:

ForEach : 0.11297199726105
MapClosure : 0.16404168605804
MapNamed : 0.11067249774933

@GrahamCampbell
Copy link
Member

@taylorotwell What if you want chained maps and filters though? That's where you see the slow down, vs doing it inline with continue statements in a foor loop.

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.

None yet

4 participants