1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00
psalm/docs/running_psalm/issues/DuplicateArrayKey.md

31 lines
491 B
Markdown
Raw Normal View History

2020-03-19 17:32:49 +01:00
# DuplicateArrayKey
Emitted when an array has a key more than once
```php
2020-03-21 00:13:46 +01:00
<?php
2020-03-19 17:32:49 +01:00
$arr = [
2020-03-21 15:13:11 +01:00
'a' => 'one',
'b' => 'two',
'c' => 'this text will be overwritten by the next line',
'c' => 'three',
2020-03-19 17:32:49 +01:00
];
```
2020-03-21 00:13:46 +01:00
## How to fix
Remove the offending duplicates:
```php
<?php
$arr = [
2020-03-21 15:13:11 +01:00
'a' => 'one',
'b' => 'two',
'c' => 'three',
2020-03-21 00:13:46 +01:00
];
```
The first matching `'c'` key was removed to prevent a change in behaviour (any new duplicate keys overwrite the values of previous ones).