Array construct/destruct should warn at least for duplicate keys
Open
Nobody has claimed this yet.
Feature
Status: Requires RFC
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
$arr = ['4', 'x' => 5];
// construct with duplicate keys
var_dump(['x' => 4, 'x' => 6]);
var_dump([2 => 4, 2.0 => 6]);
// spread operator leading to duplicate keys
var_dump(['x' => 4, ...$arr]);
// destruct with duplicate keys (it is safe to do, but if same key should be assigned to another variable too, it can be done after the destruct)
['x' => $a, 'x' => $b] = ['x' => 10];
var_dump([$a, $b]);
all cases should emit at least warning if not an error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the duplicate-key construction, spread, and destructuring examples from the issue, including the linked 3v4l.org case. Trace the PHP interpreter's handling of array keys and identify the relevant tests or entry points; done means each listed duplicate-key case emits at least a warning or error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100