Skip to content

Commit 8a46320

Browse files
fix(Collection::pop()): count < 1 (#54340)
* 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]>
1 parent 79b44b1 commit 8a46320

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,10 @@ public function select($keys)
986986
*/
987987
public function pop($count = 1)
988988
{
989+
if ($count < 1) {
990+
return new static;
991+
}
992+
989993
if ($count === 1) {
990994
return array_pop($this->items);
991995
}

0 commit comments

Comments
 (0)