Repository navigation
[12.x] Fix Arr::forget() removing the wrong element - #62410
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Arr::forget()only resets its working reference to the top-level array after the shortcut that removes an exact top-level key, so once a dotted key has been processed, the next key is checked against the nested array instead. Forgetting['users.name', 'id']from['users' => ['name' => 'Joe', 'id' => 1], 'id' => 99]removesusers.idand keeps the top-levelid. SinceArr::except(),Collection::except()and the request'sexcept()all delegate here, a list of keys an application strips from its input can silently leave one of them in place when the input nests a key of the same name.This backports #61023 from 13.x, which moves the reset to the top of the loop, together with its tests.