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

Correct parameter type of Collection::diffKeys() and Collection::diffKeysUsing() #53441

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

AJenbo
Copy link
Contributor

@AJenbo AJenbo commented Nov 7, 2024

Corrected the parameter type in the PHPDoc for Collection::diffKeys() and Collection::diffKeysUsing() from array<TKey, TValue> to array<TKey, mixed>, as these methods only operate on the keys of the given array, making the value type irrelevant.

This lets you do something like:

$animals = Animal::pluck('name', 'id');
$animalFood = Food::pluck('id', 'animal_id');

if ($animals->diffKeys($animalFood) as $id) {
    throw new Exception('Missing food for ' . $animals[$id]);
}

Tools previously flagged this usage as illegal due to the differing value types (food.id as int vs. animal.name as string), despite only the keys being compared.

@taylorotwell taylorotwell merged commit 9c86dd9 into laravel:11.x Nov 7, 2024
33 checks passed
@AJenbo AJenbo deleted the diffkeys branch November 7, 2024 22:57
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