-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Comments
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:
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... |
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 |
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. |
@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:
Apparently, we comply with |
fyi: in phpstorm we have warnings for duplicate keys in service and route files. so i will also allow this for config soon. |
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. |
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 |
I had a problem where i put
assetic:
twice inconfig_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
The text was updated successfully, but these errors were encountered: