8000 bug #28968 [OptionsResolver] Fixed explicitly ignores a depreciation … · symfony/symfony@a6e4d4a · GitHub
[go: up one dir, main page]

Skip to content

Commit a6e4d4a

Browse files
committed
bug #28968 [OptionsResolver] Fixed explicitly ignores a depreciation (yceruto)
This PR was merged into the 4.2-dev branch. Discussion ---------- [OptionsResolver] Fixed explicitly ignores a depreciation | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28860 (comment) | License | MIT | Doc PR | - When a deprecated option with default value was resolved (the first time it's called) in this case through a lazy evaluation, [the default resolution process](https://github.com/symfony/symfony/blob/8398947c9c1c1266aad0bea773d0b524e0d81643/src/Symfony/Component/OptionsResolver/OptionsResolver.php#L771-L773) takes the resolved value and here should also trigger only if the option was provided by the user or is being called from a lazy evaluation, otherwise ignore. Commits ------- 8398947 Fixed explicitly ignores a depreciation
2 parents 8c24c35 + 8398947 commit a6e4d4a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
801801

802802
// Shortcut for resolved options
803803
if (array_key_exists($option, $this->resolved)) {
804-
if ($triggerDeprecation && isset($this->deprecated[$option]) && \is_string($this->deprecated[$option])) {
804+
if ($triggerDeprecation && isset($this->deprecated[$option]) && (isset($this->given[$option]) || $this->calling) && \is_string($this->deprecated[$option])) {
805805
@trigger_error(strtr($this->deprecated[$option], array('%name%' => $option)), E_USER_DEPRECATED);
806806
}
807807

src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ function (OptionsResolver $resolver) {
754754
yield 'It explicitly ignores a depreciation' => array(
755755
function (OptionsResolver $resolver) {
756756
$resolver
757+
->setDefault('baz', function (Options $options) {
758+
return $options->offsetGet('foo', false);
759+
})
757760
->setDefault('foo', null)
758761
->setDeprecated('foo')
759762
->setDefault('bar', function (Options $options) {

0 commit comments

Comments
 (0)
0