Req #73125 [Opn]: array declaration shouldn't allow same key multiple times
| From: | requinix@php.net | Date: | Wed, 12 Dec 2018 17:12:43 +0000 |
| Subject: | Req #73125 [Opn]: array declaration shouldn't allow same key multiple times | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218425@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73125&edit=1
ID: 73125
Updated by: requinix@php.net
Reported by: sami dot vento at codeworks dot fi
Summary: array declaration shouldn't allow same key multiple
times
Status: Open
Type: Feature/Change Request
Package: Arrays related
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
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
][true];
Previous Comments:
------------------------------------------------------------------------
[2018-12-12 09:26:03] 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.
------------------------------------------------------------------------
[2016-09-20 11:20:05] sami dot vento at codeworks dot fi
Description:
------------
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);
var_dump($a);
Expected result:
----------------
notice, warning or error
Actual result:
--------------
array(1) {
["a"]=>
int(4)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73125&edit=1