当"Key repositories is a duplicate in ./composer.json"时,composer用的是哪一个?

When "Key repositories is a duplicate in ./composer.json", which one is used by composer?

我注意到我的 composer.json 中有重复的 'repositories' 键用于我正在开发的包。

包正在运行。所以,我想执行一个 'refactoring' ,我想在不改变行为的情况下修复代码。

如果我想修复错误,我将不得不删除未使用的重复密钥。

所以,问题是:

当"Key repositories is a duplicate in ./composer.json"时,composer用的是哪一个?

换句话说,

这是命令我是运行:

$ composer validate
Key repositories is a duplicate in ./composer.json at line 16
...

composer.json 看起来像这样:

{
  "name": "foo/bar",
  "description": "foo bar",
  "license": "Apache-2.0",
  "type": "library",
  "repositories": [
    {"type": "composer", "url": "foo"},
    {"packagist.org": false}
  ],

  "repositories": [
    {
      "type": "vcs",
      "url": "bar"
    }
  ],

  ...
 }

Composer 使用 seld/jsonlint to detect duplicate keys, but it uses json_decode 解码 JSON。

json_decode 使用它为键找到的最后一个值:

>>> $json = '{"a":1,"a":10,"a":100}';
=> "{"a":1,"a":10,"a":100}"
>>> $decoded = json_decode($json)
=> {#3260
     +"a": 100,
   }
>>> $decoded->a
=> 100