Skip to content

Commit

Permalink
fix(Collection::pop()): count < 1 (#54340)
Browse files Browse the repository at this point in the history
* fix(Collection::pop()): count < 1

If $count = 0 then this method was returning the same as if $count=1. If count<0 then things got worse than that. I think that in this case pop of <1 makes no sense and either we should throw an error, or we should return an empty result. I've gone with an empty result as I can see that being returned by the function anyway.

* Update Collection.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
artumi-richard and taylorotwell authored Jan 24, 2025
1 parent 79b44b1 commit 8a46320
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,10 @@ public function select($keys)
*/
public function pop($count = 1)
{
if ($count < 1) {
return new static;
}

if ($count === 1) {
return array_pop($this->items);
}
Expand Down

0 comments on commit 8a46320

Please sign in to comment.