Skip to content

Fix Cache::many() with small numeric keys - #48423

Merged
taylorotwell merged 4 commits into
laravel:10.xfrom
AlexKarpan:10.x
Sep 15, 2023
Merged

Fix Cache::many() with small numeric keys#48423
taylorotwell merged 4 commits into
laravel:10.xfrom
AlexKarpan:10.x

Conversation

@AlexKarpan

Copy link
Copy Markdown
Contributor

Cache::many([1,2,3]) for an empty cache returns [1 => 2, 2 => 3, 3 => null] instead of [1 => null, 2 => null, 3 => null].
String keys like this \Cache::many(['1','2','3']) make no difference.

The issue is that Illuminate\Cache\Repository tries to set default values for missing keys, and in case of small numeric keys it treats those as positions: e.g. when $keys = [1, 2, 3] the value of $keys[1] is 2.

This code in this PR tests if $keys is not an associative array (in other words, it doesn't contain the defaults, just the keys) and if so, just returns null for missed cache keys.

@taylorotwell
taylorotwell merged commit f0d949b into laravel:10.x Sep 15, 2023
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