Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

@derrabus
Copy link
Member

@derrabusderrabus commentedNov 5, 2020
edited by nicolas-grekas
Loading

QA
Branch?6.2
Bug fix?no
New feature?no
Deprecations?yes
TicketsN/A
LicenseMIT
Doc PRN/A

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 fromTokenStorageInterface:

publicfunction setToken(TokenInterface$token =null);

This means that those to calls are equivalent:

$tokenStorage->setToken(null);$tokenStorage->setToken();

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 declarenull 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.

publicfunction setToken(?TokenInterface$token);

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 forTokenStorageInterface 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.

ro0NL and HypeMC reacted with thumbs up emoji
@derrabusderrabus added this to the5.x milestoneNov 5, 2020
@derrabusderrabusforce-pushed theimprovement/nullable-setters branch 2 times, most recently from729ead4 tocf1e8baCompareNovember 5, 2020 00:16
@derrabusderrabusforce-pushed theimprovement/nullable-setters branch fromcf1e8ba to97aa4b6CompareNovember 5, 2020 20:24
@derrabusderrabus marked this pull request as draftNovember 5, 2020 23:04
@Nyholm
Copy link
Member

I like this idea. Do you need help to finish this PR?

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedApr 12, 2021
edited
Loading

This is a hard BC break that provides no BC layer unfortunately. A given implementation cannot be made compatible with v5 and v6 at the same time. I think this makes this change impossible, following our policy.

@derrabus
Copy link
MemberAuthor

This is a hard BC break that provides no BC layer unfortunately. A given implementation cannot be made compatible with v5 and v6 at the same time.

Can you elaborate?

@fabpotfabpot modified the milestones:5.4,6.1Nov 3, 2021
@fabpot
Copy link
Member

Unlocked :)

@nicolas-grekas
Copy link
Member

So, I was wrong about the BC break 😬
Let's rebase and merge this?

@derrabus
Copy link
MemberAuthor

I'll try to find some time to resume my work. 🤞

@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@nicolas-grekasnicolas-grekas marked this pull request as ready for reviewSeptember 12, 2022 12:33
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment
edited
Loading

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)

derrabus reacted with heart emoji
@nicolas-grekasnicolas-grekasforce-pushed theimprovement/nullable-setters branch 3 times, most recently frome24fc67 to56532ebCompareSeptember 12, 2022 14:07
@derrabus
Copy link
MemberAuthor

Thank you! ❤️

@nicolas-grekas
Copy link
Member

Thank you@derrabus.

@nicolas-grekasnicolas-grekas merged commitfc550ea intosymfony:6.2Sep 12, 2022
@derrabusderrabus deleted the improvement/nullable-setters branchOctober 13, 2022 13:26
@fabpotfabpot mentioned this pull requestOct 24, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrchalasr approved these changes

@wouterjwouterjAwaiting requested review from wouterjwouterj is a code owner

@lyrixxlyrixxAwaiting requested review from lyrixxlyrixx is a code owner

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

@xabbuhxabbuhAwaiting requested review from xabbuhxabbuh is a code owner

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

6 participants

@derrabus@Nyholm@nicolas-grekas@fabpot@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp