8000 Changed private static properties to private const by simonberger · Pull Request #38213 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Changed private static properties to private const #38213

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

Closed

Conversation

simonberger
Copy link
Contributor
@simonberger simonberger commented Sep 16, 2020
Q A
Branch? master
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR changes all private static properties with read-only usage to private const.

@nicolas-grekas nicolas-grekas added this to the next milestone Sep 16, 2020
@simonberger simonberger force-pushed the private-static-to-const branch from 96f279a to 8834baa Compare September 16, 2020 17:00
@stof
Copy link
Member
stof commented Sep 16, 2020

changing this only in master will make maintenance harder (we will get potential conflicts on all these places for each merge-up), while this provides little benefit.

As this applies only to private stuff, this can be changed at any time without any BC impact. So if we decide to apply such change on existing code, I would suggest doing that in the oldest supported branch, so that all maintained branches have that and don't conflict when merging up later. But given private const requires PHP 7.1, such change cannot be applied to the 3.4 branch. So using that strategy would require waiting for 3.4 to reach end of bug fix support, i.e. waiting until end of November 2020.

@simonberger
Copy link
Contributor Author
simonberger commented Sep 16, 2020

@stof
I would understand such a decision.
I just like this change to happen. Static const-like usage always reminds me of old code.

Whenever you decide to release this.
I like to not stop after changing private static but also protected and public static usage of the same way, This obviously would mean deprecating the old property and and having both for the rest of the 5.x releases.

Please let me also know if this is something you support.

@simonberger simonberger force-pushed the private-static-to-const branch from 2c6c101 to d16a487 Compare September 16, 2020 17:46
@derrabus
Copy link
Member

I agree that this would be a reasonable code modernization. If we do it, the patch should be applied to the 4.4 branch after the final bugfix release of the 3.4 branch.

@simonberger simonberger marked this pull request as ready for review September 16, 2020 17:57
@simonberger
Copy link
Contributor Author
simonberger commented Sep 16, 2020

Ready for review generally.
But I'll close it in a few days if its the decision to wait. No need to look at the code right now.

@simonberger
Copy link
Contributor Author

An example which public static properties to potentially change is:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Response.php#L147

The backward compatibility is rather easy as it is possible to assign the value of the new const to the static property.

I admit changing this with the necessary deprecation means a lot of documentation for this rather small change and is maybe not reasonable. On the other hand it is the only way to get rid of it with the clean upgrade strategy Symfony has.

@stof
Copy link
Member
stof commented Sep 16, 2020

I admit changing this with the necessary deprecation means a lot of documentation for this rather small change and is maybe not reasonable.

it even involves replacing the public property with a magic one. Otherwise, we have no way to trigger deprecations when using it.

@simonberger
Copy link
Contributor Author

Yes, if there is a requirement of a thrown message this is necessary. But that's not a much higher complexity.
From your doubts for this PR; As the public static code changes can only be done in the master this probably would be the biggest impact for the development.

@ro0NL
Copy link
Contributor
ro0NL commented Sep 17, 2020

@stof soft-deprecating public static props would work, isnt it? AFAIK we cant even overload static props in php ..., so my proposal would be

/** @deprecated use class::X instead */
public static $x = self::X;
public const X = ...;
```

@stof
Copy link
Member
stof commented Sep 17, 2020

@ro0NL we cannot warn for such deprecation, so it might not be enough for projects to migrate.

And indeed, for static props, the trick of the magic property won't work.

@nicolas-grekas
Copy link
Member

I think this might be worth doing in 4.4 immediately. I don't think 3.4 will evolute that much around those lines in the next 3 months.

@ro0NL
Copy link
Contributor
ro0NL commented Sep 17, 2020

it might not be enough for projects to migrate

we could try :)

@simonberger
Copy link
Contributor Author

If you accept it for 4.4 at this point I'll redo it on this branch. Let me know if this has been decided.

Regarding public/protected deprecation:
If showing the deprecation in the code and having the upgrade notes is enough, it is easily done.
There are several request for static magic functions but nothing seem to happen.

@simonberger
Copy link
Contributor Author

@stof @xabbuh @dunglas Do you want those changes for 4.4
now 👍
or later 👎
?
I'll close the MR this week but re-create it for 4.4 if no one comments/votes to do this later.

@stof
Copy link
Member
stof commented Sep 22, 2020

if @nicolas-grekas is OK with doing it now in 4.4 rather than waiting, this is fine with me. He is the one doing the merge-up regularly, not me, so I will accept it if he thinks that the 2 months delay is not necessary.

@fabpot
Copy link
Member
fabpot commented Sep 22, 2020

Let’s wait the end of 3.4 first.

@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
nicolas-grekas added a commit that referenced this pull request Jan 25, 2021
…erger)

This PR was merged into the 4.4 branch.

Discussion
----------

Changed private static array-properties to const

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| License       | MIT

This changes all private static properties (just screened arrays) to private const. I left out those which have write access obviously and also those with `static::` access.

It is a new implementation of #38213. Based on 4.4 this time.
If merging it up creates several conflicts, you could ignore all changes of 4.4 and I create a new branch for 5.1 or 5.2. I'll do this anyway if any new private static arrays are existing there.

Commits
-------

aa79381 Changed private static array-properties to const
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0