0
What are the difference between abstract class and interfaces in php?
Oops
3 Answers
+ 8
Xan Yeah right..
thanks for your information too đđ
+ 7
Interfaces
An interface is a contract: The guy writing the interface says, "hey, I accept things looking that way", and the guy using the interface says "OK, the class I write looks that way".
An interface is an empty shell. There are only the signatures of the methods, which implies that the methods do not have a body. The interface can't do anything. It's just a pattern.
Abstract classes
Abstract classes, unlike interfaces, are classes. They are more expensive to use, because there is a look-up to do when you inherit from them.
Abstract classes look a lot like interfaces, but they have something more: You can define a behavior for them. It's more about a guy saying, "these classes should look like that, and they have that in common, so fill in the blanks!".
SOURCE:
https://stackoverflow.com/questions/1913098/what-is-the-difference-between-an-interface-and-abstract-class
FOR MORE:
https://codeinphp.github.io/post/abstract-class-vs-interface/
https://www.quora.com/What-is-different-between-abstract-class-and-interface-in-PHP
+ 1
Baraa AB Nailed it.
Abstract classes can't be instantiated into objects... you have to inherit them to do that.
Example, we might not want a base class like Animal to exist in a game, because we don't want a generic animal existing! But we do want a Dog object that inherits from Animal to exist. If Animal wasn't abstract, then people could create an object Animal, which we don't want to happen.