8000 double keys in configuration warning · Issue #11538 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

double keys in configuration warning #11538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
flip111 opened this issue Aug 1, 2014 · 7 comments
Closed

double keys in configuration warning #11538

flip111 opened this issue Aug 1, 2014 · 7 comments
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Yaml

Comments

@flip111
Copy link
Contributor
flip111 commented Aug 1, 2014

I had a problem where i put assetic: twice in config_prod.yml by accident. Because of that it didn't work as i expected. It would be nice if symfony throws a warning for this instead of just overriding/ignoring. Perhaps part of developer experience.

Edit: when throwing a warning the parsing can continue

@wouterj
Copy link
Member
wouterj commented Aug 1, 2014

I don't think we can do anything about this. The configuration doesn't get duplicated keys, since PHP doesn't accept duplicated keys (just like any other language, including Yaml).

The Yaml parser can't throw an exception here, since the Yaml spec states the following:

It is an error for two equal keys to appear in the same mapping node. In such a case the YAML processor may continue, ignoring the second key: value pair and issuing an appropriate warning. This strategy preserves a consistent information model for one-pass and random access applications.

The Yaml parser does a perfect job following this spec currently:

use Symfony\Component\Yaml\Parser;

$parser = new Parser();

var_dump($parser->parse(<<<EOY
assetic:
  use_controller: true

assetic:
  use_controller: false
EOY
));
/* RESULT:
Array (
    [assetic] => Array (
        [use_controller] => true
    )
)
*/

Woeps, got a very important typo here...

@flip111
Copy link
Contributor Author
flip111 commented Aug 1, 2014

Since the parsing is done in PHP see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Yaml/Parser.php you can use array_key_exist() to check if the key has already been registered before. If so then store the key name in an array $doubleKeys or something like this.

@fabpot
Copy link
Member
fabpot commented Aug 1, 2014

Being able to have duplicate keys is a YAML features, so there is nothing wrong here. I do understand the frustration, but that's how YAML works.

@javiereguiluz
Copy link
Member

@wouterj you say that "The Yaml parser does a perfect job following this spec currently", but this is only half-true. As you said, the YAML standard states the following:

It is an error for two equal keys to appear in the same mapping node. In such a case, the YAML processor may continue:

  1. ignoring the second key: value pair;
  2. and issuing an appropriate warning.

This strategy preserves a consistent information model for one-pass and random access applications.

Apparently, we comply with 1. but not with 2.

@Haehnchen
Copy link
Contributor

fyi: in phpstorm we have warnings for duplicate keys in service and route files. so i will also allow this for config soon.

@stof stof added Yaml labels Aug 18, 2014
@wouterj
Copy link
Member
wouterj commented Sep 8, 2014

I think it's safe to close this one. There is currently no warning system in the Yaml parser. Adding one (while still continuening parsing the file) will add overhead on the Yaml parser with little gain.

@sampart
Copy link
sampart commented Mar 14, 2017

In case anyone else finds this via Google like me, I thought it worth adding a quick update. "Deprecated defining duplicated keys" is one of the changes in Symfony 3.2, and in Symfony 4.0, duplicated keys will result in a ParseException. See http://symfony.com/blog/new-in-symfony-3-2-yaml-deprecations#deprecated-defining-duplicated-keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) Yaml
Projects
None yet
Development

No branches or pull requests

7 participants
0