🐘 PHP Beginner

What is an abstract class in PHP?

Answer

An abstract class is a class declared with the abstract keyword that cannot be instantiated directly — it must be subclassed. It can contain a mix of abstract methods (declared without implementation, which subclasses must provide) and concrete methods (with implementation, which subclasses inherit). abstract class Shape { abstract public function area(): float; public function describe(): string { return "I am a shape"; } }. Use abstract classes when you want to share code among closely related classes while enforcing a common interface. The key difference from interfaces: abstract classes can have instance variables, constructor logic, and concrete methods. A class can only extend one abstract class.