-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[3.0] Final classes by default #15233
Comments
👎 |
@unkind only for classes implementing interfaces and ONLY the interface methods as public API. |
In my opinion we don't need to introduce this as general rule, but we could indeed spent some time about thinking whether or not a new class really deserves to be extendable (removing |
@Ocramius yes, it can sound like that, less strict, but still reasonable. However, I usually mark almost every class in my projects. Why do you need to inherit value objects like
Yes, but at least marking as
|
In a framework, it is very hard to foresee what users are going to use your classes for. |
Symfony has IMO, it makes sense to allow
|
@unkind that's good enough for me :-) |
Closing this generic issue. Let's add final where it makes sense. |
Just to make sure our conversation from #19891 won't be lost:
|
Quite some years later, I find this post and I'm wondering why @fabpot said "Let's add final where it makes sense." and Symfony still does not implement this convention by default or gives an option to create classes with this keyword because I see many Symfony developers adding "final" themselves on controllers, services etc.... I might be missing something here.. ?? |
Two quick comments: the important part of the sentence is "where it makes sense", which means that the context is important and this should always be a conscious decision. Also, the rules that make sense for a framework like Symfony rarely make sense for applications. |
There is a rule in Symfony to make all non-public class members
private
by default, notprotected
:by @jakzal (#14923).
I suggest to make BC policy more strict for Symfony 3: require
final
on every new class by default. Reasoning is simple: if you don't think that class should be inherited, then don't leave it opened for inheritance, it would allow to keep BC better. Sometimes I see PRs which technically break BC, but it is allowed because "it's too rare and weird case to inherit that class". To be consistent, you shouldn't allow to inherit that class then. Later you can removefinal
keyword if there is valid use case for inheritance.I can refer to some similar opinions:
The text was updated successfully, but these errors were encountered: