mirror of
https://github.com/danog/psalm.git
synced 2024-12-15 02:47:02 +01:00
3ce41d71a4
* Clean up issues list, add documentation to help with named variadic confusion. * Add ComplexFunction and ComplexMethod back to issues list. I removed them because the documentation files don't exist, but they're used and the documentation just needs to be added.
730 B
730 B
DuplicateArrayKey
Emitted when an array has a key more than once
<?php
$arr = [
'a' => 'one',
'b' => 'two',
'c' => 'this text will be overwritten by the next line',
'c' => 'three',
];
This can be caused by variadic arguments if @no-named-arguments
is not specified:
<?php
function foo($bar, ...$baz): array
{
return [$bar, ...$baz]; // $baz is array<array-key, mixed> since it can have named arguments
}
How to fix
Remove the offending duplicates:
<?php
$arr = [
'a' => 'one',
'b' => 'two',
'c' => 'three',
];
The first matching 'c'
key was removed to prevent a change in behaviour (any new duplicate keys overwrite the values of previous ones).