What is object-oriented programming (OOP) 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
PHP supports full object-oriented programming starting from PHP 5. OOP in PHP includes: Classes (blueprints with properties and methods), Objects (instances created with new), Encapsulation (access modifiers: public, protected, private), Inheritance (a class extends another using extends), Polymorphism (overriding methods in subclasses), Abstraction (abstract classes and interfaces), Traits (horizontal code reuse without inheritance). PHP supports single inheritance for classes but multiple interface implementation. OOP allows for better code organization, reusability, and maintainability compared to procedural PHP code.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex PHP answers easy to follow.
Previous
What is SQL injection and how do you prevent it in PHP?
Next
What is a PHP class and how do you create one?