php / php/php-src

Array construct/destruct should warn at least for duplicate keys

Open
#9,848 6 comments 0 reactions 0 assignees View on GitHub

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]);

https://3v4l.org/NTFPM

all cases should emit at least warning if not an error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.