What is an abstract class in PHP?
Why Interviewers Ask This
This is a classic screening question for PHP roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
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.
Pro Tip
This topic has PHP-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.