Req #73125 [Opn->Sus]: array declaration shouldn't allow same key multiple times
| From: | cmb@php.net | Date: | Tue, 09 Mar 2021 13:20:26 +0000 |
| Subject: | Req #73125 [Opn->Sus]: array declaration shouldn't allow same key multiple times | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232638@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: cmb@php.net
Reported by: sami dot vento at codeworks dot fi
Summary: array declaration shouldn't allow same key multiple
times
-Status: Open
+Status: Suspended
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 â¦
Indeed, that may break valid code. Anybody who is interested in
this feature, please pursue the RFC process[1]. For the time
being, I suspend this ticket.
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2018-12-12 17:12:43] requinix@php.net
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];
------------------------------------------------------------------------
[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