Laravel Version
laravel 12
PHP Version
8.5.3
Database Driver & Version
No response
Description
I encountered unexpected behavior in Arr::forget when deleting multiple keys in a single call. The issue appears to be caused by $array not being reset to the original reference before calling static::exists() inside the foreach loop.
Expected Result
[
'user' => [
'test' => 'user.test',
],
]
Actual Result
[
'user' => [],
'test' => 'test'
]
The $array variable may still reference a nested sub-array from the previous iteration (due to $array = &$array[$part]; inside the while loop). Since $array is not reset to $original before the exists() check, the existence check may be performed on the wrong array level.
Steps To Reproduce
$array = [
'user' => [
'name' => 'user.name',
'test' => 'user.test',
],
'test' => 'test'
];
Arr::forget($array, ['user.name', 'test']);
return $array;
Laravel Version
laravel 12
PHP Version
8.5.3
Database Driver & Version
No response
Description
I encountered unexpected behavior in Arr::forget when deleting multiple keys in a single call. The issue appears to be caused by $array not being reset to the original reference before calling static::exists() inside the foreach loop.
Expected Result
[
'user' => [
'test' => 'user.test',
],
]
Actual Result
[
'user' => [],
'test' => 'test'
]
The $array variable may still reference a nested sub-array from the previous iteration (due to $array = &$array[$part]; inside the while loop). Since $array is not reset to $original before the exists() check, the existence check may be performed on the wrong array level.
Steps To Reproduce
$array = [
'user' => [
'name' => 'user.name',
'test' => 'user.test',
],
'test' => 'test'
];