-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 our terms of service and privacy 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
Conversation
729ead4
to
cf1e8ba
Compare
src/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php
Outdated
Show resolved
Hide resolved
cf1e8ba
to
97aa4b6
Compare
I like this idea. Do you need help to finish this PR? |
|
Can you elaborate? |
Unlocked :) |
So, I was wrong about the BC break 😬 |
I'll try to find some time to resume my work. 🤞 |
97aa4b6
to
bafbd28
Compare
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
to
56532eb
Compare
Thank you! ❤️ |
56532eb
to
78803b2
Compare
Thank you @derrabus. |
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
null
as 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
TokenStorageInterface
andContainerAwareInterface
, 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.