Interface Default Methods

Read the RFC
93
169 yes
258 no

Interface Default Methods improves backwards compatibility when changing interfaces, but also add a way to have multi-inheritance in PHP.

Click the bar to cast your vote!
40%
60%
1

but also add a way to have multi-inheritance in PHP.

I consider that allowing multiple inheritance is a mistake, since inheritance is something that in more than 90% of cases is a premature and erroneous abstraction of reality.

Share:
khru avatar
khru
voted no
1

Traits already cover the use case.

Share:
kyriakos avatar
kyriakos
voted no
1

I like how this solves updating existing interfaces without breaking user facing code.

Share:
thomasalrek avatar
thomasalrek
voted yes
1

C# has it and I want it in PHP too. It is very handy for implementing new interfaces with simple getters for example.

Share:
ricardo avatar
ricardo
voted yes
1

I'm against a multi-inheritance in OOP. I don't think this RFC is necessary for the language. The current OOP system in PHP is already well developed.

Share:
Contributor serhii avatar
serhii
voted no
1

if you need a default method implementation, then use an abstract class. And inheritance, especially multiple, contradicts half of the principles of SOLID. Use composition whenever you can and you will be happy.

Share:
stolentine avatar
stolentine
voted no
1

We already have solutions to both problems, with traits and class inheritance.

Share:
thallisphp avatar
thallisphp
voted no
1

The promised backwards compatability was never a real feature. You can still get name clashes with existing methods. So its a new feature promising something that will never happen. It got rejected for good reasons.

Share:
tpetry avatar
tpetry
voted no
1

Brings ambiguity, violates single responsibility. Interfaces for contracts, handle defaults with concrete/abstract classes. Code becomes clearer, more maintainable.

Share:
phcostabh avatar
phcostabh
voted no
1

I've written DefaultImplementation traits to implement common interface functionality one too many times. Would love to see this as a feature.

Share:
moebrowne avatar
moebrowne
voted yes
1

it works in other languages pretty well, and i think it's not a bad thing to have more than one way to do something.

Share:
roeycohen avatar
roeycohen
voted yes
1

This seems like a solution to a design problem rather than a language problem. I feel like the specific examples aren't something that I've come across frequently enough to add to the language. If we're looking at a pure OOP perspective, Interfaces enforce behaviour. If you're also supplying the behaviour in cases where you don't expect there to always need to be an implementation that really smells like a poorly designed interface.

Share:
nathansalter avatar
nathansalter
voted no
1

With our current definition of an interface this RFC seems silly - but i really think that this could allow for faster and easier development (less files, less duplicated code...).

Just today while coding i had an example of an interface where one of the abstract functions would be the same 99% of the time. Creating a trait for a 4 liner function seems overkill - but the alternative is to duplicate the code almost everytime.

Share:
simonvanacco avatar
simonvanacco
voted yes
1

Multiple inheritance is probably a better solution. It's something that already exists in other languages and which we can certainly reimplement using their same solutions to the same problems (e.g. conflicting methods and properties). The functionality would then be more powerful and complete than this RFC.

Share:
sukei avatar
sukei
voted no
1

..a controversial one indeed. Personally I would try to avoid this feature in my own code (just like I avoid traits and abstract classes because I feel that they are a sign of bad abstractions).

To me the fact that convinced me is the last section of the RFC:

This feature may be used to enhance existing interfaces in PHP. Countable could add function isEmpty(): bool { return $this->count() == 0; }. Iterator could add methods like map, filter, and reduce which behave similarly to array_map, array_filter, and array_reduce.

Share:
bastian avatar
bastian
voted yes
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!