Skip to content

[OptionsResolver] Fixed unexpected behavior when using setOptional + setNormalizers #6233

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
wants to merge 1 commit into from

Conversation

boekkooi
Copy link
Contributor

@boekkooi boekkooi commented Dec 7, 2012

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #6215
License of the code: MIT

@@ -500,12 +500,14 @@ private function normalize($option)
throw new OptionDefinitionException('The options "' . implode('", "', $conflicts) . '" have a cyclic dependency.');
}

/** @var \Closure $normalizer */
$normalizer = $this->normalizers[$option];
if (array_key_exists($option, $this->options)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to not call $this->normalize at all (in all()) in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion since a call to unset($this->normalizers[$option]); is contained in this function I feel that moving this check to all() could lead to confusion and possibly unexpected behavior later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can there be a lock on an option that does not exist yet when normalizing? I don't think so. So you could move the array_key_exists check above if (isset($this->lock[$option])) { which saves a method call. Or as I suggested above put this logic in all so even save the method call to normalize. Somy tiny code duplication is prefered compared to slowing the code that is executed thousands of times.

@webmozart
Copy link
Contributor

We cannot fix this without breaking BC (see #9174). Postponed to 3.0.

@webmozart webmozart closed this Sep 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants