|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73125 array declaration shouldn't allow same key multiple times
Submitted: 2016-09-20 11:20 UTC Modified: 2018-12-12 17:12 UTC
Avg. Score:1.0 ± 0.0
Reproduced:0 of 2 (0.0%)
From: sami dot vento at codeworks dot fi Assigned:
Status: Open Package: Arrays related
PHP Version: 7.0.11 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
13 + 42 = ?
Subscribe to this entry?

 [2016-09-20 11:20 UTC] sami dot vento at codeworks dot fi
Defining array with single clause should check duplicate keys and at least warn user. Current implementation just takes last defined value for key.

Test script:
$a = array('a'=>3, 'a'=>4);

Expected result:
notice, warning or error

Actual result:
array(1) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-12 09:26 UTC] daniele dot maggio at dotnext dot it
Sorry but I think it's not a bug;

it is correct that your value is overwrited since you use a text key, The matter is how you use things.
 [2018-12-12 17:12 UTC]
Personally, I would be disappointed to see this implemented as I sometimes use it in place of a long if or ternary, like

$value = [
  true => "default", // lowest priority
  $some_condition => "some value",
  $other_condition => "other value",
  $final_condition => "final value" // highest priority
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Feb 25 22:01:25 2020 UTC