Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[OptionsResolver] Allow deprecations to be overridden with an empty s…#62345
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
yceruto commentedNov 8, 2025
I'm not sold by this change. Could you elaborate a bit more on when this would be useful? |
yceruto commentedNov 8, 2025
It looks to me like a new feature intended to remove a deprecation notice. |
yoeunes commentedNov 8, 2025
Hi@yceruto, thanks for the feedback. You are absolutely right, thischanges an existing behaviour. My apologies for misclassifying it. The use case I had in mind is to allow child classes to override a deprecation set by a parent class. Without this change, it's impossible for a child class to cancel a deprecation. Imagine a base // In MyBundle/Form/BaseType.phppublicfunctionconfigureOptions(OptionsResolver$resolver){$resolver ->setDefined(['hostname','host']) ->setDeprecated('hostname','my/bundle','1.0','The option "%name%" is deprecated, use "host" instead.' );} Now, in a child class extending it, you might want to re-enable 'hostname' without deprecation (maybe for backward compatibility in a specific context): // In src/Form/AppType.phppublicfunctionconfigureOptions(OptionsResolver$resolver){parent::configureOptions($resolver);// This call is the new behavior$resolver->setDeprecated('hostname','my/bundle','1.1','');// Should disable the prior deprecation} Do you think this capability is a valuable addition? If so, I am happy toclose this PR and re-open it against the Please let me know what you think. |
yceruto commentedNov 8, 2025
Hi, thanks for clarifying the use case. I don't think that change is needed though, you can already redefine the same option even if it's marked as deprecated. The resolver will apply your new definition, and you can simply ignore the deprecation triggered by the parent class. Once the deprecated option is eventually removed upstream, your redefinition will seamlessly take over without issues. |
yceruto commentedNov 8, 2025
I'm still considering whether this is a valid use case, and why you can't use the |
yceruto commentedNov 8, 2025
Another alternative is to remove the option before redefining it, clearing any parent definition. $resolver->remove('hostname');$resolver->define('hostname'); I just checked the remove method, and it seems we missed unsetting the deprecated option, if any. PR welcome! |
nicolas-grekas commentedNov 8, 2025
I'm like Yonel. There need to be a real world use case and I'm not sure there's one at the moment. We might actually consider that an empty deprecation message should throw. If we did so, would any use case be impossible? I don't see when. |
yoeunes commentedNov 8, 2025
Hi@yceruto and@nicolas-grekas, thank you both for your feedback. You are right, my original use case was flawed. Using @nicolas-grekas To answer your question: I agree. After this discussion, and assuming I have just created the new PR to fix As this PR is not the correct approach, I am closing it. |
This PR fixes a bug that prevented a previously set deprecation from being cancelled. If
setDeprecated()was called with an empty string, it would returnvoidwithout removing the existing deprecation entry.This made it impossible for child classes or subsequent configurations to override and disable a deprecation set by a parent configuration.
The fix ensures that calling
setDeprecated('...', '')activelyunset()s the deprecation from the internal array, restoring the expected override behavior.Example:
Given a base configuration (e.g., a parent class) that deprecates the
hostnameoption, based on the documentation's example:A child configuration attempts toannul this deprecation:
Before (The Bug):
The
isDeprecated('hostname')method still returnedtrue, and resolving['hostname' => '...']would incorrectly trigger anE_USER_DEPRECATEDerror.After (The Fix):
The deprecation is correctly removed.
isDeprecated('hostname')now returnsfalse, and no deprecation error is triggered when resolving the option.