Does PHP have an open implementation for abstract interfaces?

The concept that I think comes from the Traversable interface. This interface cannot be implemented directly, but instead an interface is implemented that extends it.

Can I declare an interface that cannot be implemented and extend it using public interfaces?

Edit: I understand that the opportunity would be completely pointless, as it could be circumvented by a third-party interface developer who could extend the base interface. I am looking for a cleaner way to express polymorphism.

For example:

abstract interface Vehicle { } interface Car extends Vehicle { public function drive(RouteProvider $routeProvider, $speed) } interface Boat extends Vehicle { public function sail(BodyOfWater $water, $heading); } class PeopleMover { public function move(Vehicle $vehicle) { if ($vehicle instanceof Boat) { // move people across bodies of water } elseif ($vehicle instanceof Car) { // move people along roads } } } 
+7
oop php abstract
source share
1 answer

The purpose of the interface is to determine how the application accesses your object, but rather controls how the objects are defined. This is a way for your object to point to the application: "I am implementing this interface, so you can trust me that I have these methods."

If you want to control how objects are defined, you must use abstract classes with abstract methods.

+1
source share

All Articles