Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Remove the default values from setters with a nullable parameter#38996
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
Remove the default values from setters with a nullable parameter#38996
Uh oh!
There was an error while loading.Please reload this page.
Conversation
729ead4 tocf1e8baComparesrc/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
cf1e8ba to97aa4b6CompareI like this idea. Do you need help to finish this PR? |
nicolas-grekas commentedApr 12, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
Can you elaborate? |
Uh oh!
There was an error while loading.Please reload this page.
Unlocked :) |
So, I was wrong about the BC break 😬 |
I'll try to find some time to resume my work. 🤞 |
97aa4b6 tobafbd28Compare
nicolas-grekas left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
(I rebased and completed the patch)
e24fc67 to56532ebCompareThank you! ❤️ |
Uh oh!
There was an error while loading.Please reload this page.
56532eb to78803b2CompareThank you@derrabus. |
Uh oh!
There was an error while loading.Please reload this page.
Setters with a default value are a bit odd: I want to set a value, but I won't tell you which one!
We do have this kind of setters, like this example from
TokenStorageInterface:This means that those to calls are equivalent:
The reason for this is actually a php 5 quirk: On php 5, we did not have nullable parameter type declarations – those we added in php 7.1. The only workaround was to declare
nullas default value because then php would accept passing null despite the type declaration demanding an instance of a specific class/interface.Because the days of php 5 are over, I'd like to change this. Our method signature would then look like this.
We can do this for interfaces and abstract methods because an implementation may add a default value. Thus, removing the default value from the interface alone is not a BC break.
For the implementations of that interface, this is a different story because removing the default breaks calling code that omits the parameter entirely. This is why for the implementations I trigger a deprecation if the method is called without arguments. This enables us to remove the default in Symfony 6.
This PR performs the suggested changes for
TokenStorageInterfaceandContainerAwareInterface, but we have a few more setters like this. But before I continue, I'd like to collect some feedback if this is something you would want to change.