Replies: 1 comment 9 replies
-
But why? It must return the item it removes AS IS, that's what shifting always did no matter the language or the object it was on, it returns the value it removes. |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The current behavior of Collection->shift() (since merging #51686) is:
shift(0)
returns a Collectionshift(1)
returns a single itemshift(2)
returns a Collectionshift(3)
returns a CollectionThis can easily lead to bugs (as just happened to me) if you pass a variable as the parameter, e.g.
shift($count)
.A current workaround is to use
Collection::wrap($coll->shift($count))
, but it's not immediately obvious that such a wrapper exists, or that it's necessary to use it.I propose adding an optional second boolean parameter to shift() which forces it to always return a Collection, even when shifting exactly one element. So that:
shift(0, true)
returns a Collectionshift(1, true)
returns a Collectionshift(2, true)
returns a Collectionshift(3, true)
returns a Collectionwhereas
shift(1)
remains backwards-compatible.Beta Was this translation helpful? Give feedback.
All reactions