-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Allow declaring abstract final
methods or classes to allow interface
/abstract class
providers to enforce exactly one non-abstract
child implementation
#18118
Comments
abstract final
methods or classes to allow interface
/abstract class
providers to enforce _exactly one_ non-abstract
child implementationabstract final
methods or classes to allow interface
/abstract class
providers to enforce exactly one non-abstract
child implementation
Hi @stepo2 Your definition of I'm also unsure what use-cases this feature would actually solve. Can you elaborate on that? In any case, this is likely controversial enough to require an RFC. Check out the howto guide on how to do that. The first step is sending an e-mail to the internals mailing list and seeing how your idea is perceived. |
If re-using
For once, pure academic completeness. I can use PHP without declaring any explicit types, but I also optionally can use PHP to declare types and enforce them. I can use classes without write-access - I can however also optionally enforce them as such by using But to come to the real world: some languages have classes " |
There was a discussion about this from a decade ago that might be a worthwhile addition to this conversation: |
Thanks for the link. Given that this was RFC'd before and declined, introducing this change would definitely require a new RFC. |
Also note that the linked RFC has a different semantic meaning for
But what you can't do is to omit a type, while enforcing the child to declare one. That's closer what this new keyword would do.
Sure, I agree. But this seems like the wrong way to enforce that. 1. Many classes are deeply nested without implementing an interface or inheriting an abstract class. 2. The very point of an interface is to abstract away the details of a class. Why then does it care whether the class has sub-classes? My feelings aside, I think the only way for this to move forward is to discuss it on the internals mailing list. If you would like to see this happen, please push the discussion forward. Thank you for the proposal! |
Description
I always wondered why PHP does not allow
abstract final
methods or classes. This way aninterface
or anabstract class
could enforce that only the first non-abstract
child class in the hierarchy must implement the class or the method body, preventing further inheritance of the class/method.Of course, the implementor of the first non-
abstract
class/method can optionally mark the first implementation asfinal
already if he likes. But theinterface
/abstract
provider currently can not enforce this, however. If it is optionally implementable from the concrete child perspective it should also be optionally enforcable from the abstract parent perspective.The text was updated successfully, but these errors were encountered: