Skip to content

[12.x] Fix Arr::forget() removing the wrong element - #62410

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
GrahamCampbell:12.x-arr-forget
Nov 11, 2026
Merged

taylorotwell merged 1 commit into
laravel:12.xfrom
GrahamCampbell:12.x-arr-forget

Conversation

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

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] removes users.id and keeps the top-level id. Since Arr::except(), Collection::except() and the request's except() 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.

@taylorotwell
taylorotwell merged commit 59f710c into laravel:12.x Nov 11, 2026
72 checks passed
@GrahamCampbell
GrahamCampbell deleted the 12.x-arr-forget branch November 12, 2026 00:32
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.

2 participants