Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Sep 15, 2023
Merged

Conversation

AlexKarpan
Copy link
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
18 of 20 checks passed
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.

None yet

2 participants