🐘 PHP Intermediate

What is the difference between abstract methods and interface methods in PHP?

Why Interviewers Ask This

This question targets practical, hands-on experience with PHP. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

Answer

Both abstract methods (in abstract classes) and interface methods define a contract that implementing/extending classes must fulfill, but they exist in different contexts. Abstract methods are declared in an abstract class with the abstract keyword and can be public or protected. The abstract class may also contain concrete methods, state (instance variables), and a constructor. Interface methods are implicitly public and abstract — they define what must be done without any implementation context. A class can only extend one abstract class (single inheritance) but implement multiple interfaces. Use abstract classes when subclasses share state or partial implementation; use interfaces to define capabilities for unrelated classes. Since PHP 8.0, interfaces can also have constants.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last PHP project, I used this when...' immediately makes your answer more credible and memorable.