🟢 Basic OOP Interview Questions
1. What is OOP in PHP?
OOP (Object-Oriented Programming) is a programming paradigm based on classes and objects. It helps organize code using:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
2. What is a Class and Object?
- Class → Blueprint of an object
- Object → Instance of a class
class Car {
public $brand = "BMW";
}$car = new Car(); // object
3. What is a Constructor?
A constructor is a special method called automatically when an object is created.
class Test {
public function __construct() {
echo "Object Created";
}
}
4. What is a Destructor?
It is called when an object is destroyed.
public function __destruct() {
echo "Object Destroyed";
}
🟡 Intermediate Questions
5. What is Encapsulation?
Wrapping data and methods into a single unit and restricting access using:
- private
- protected
- public
6. What is Inheritance?
Acquiring properties and methods of another class.
class ParentClass {}
class ChildClass extends ParentClass {}
7. What is Polymorphism?
Same method, different behavior.
class A { function test(){ echo "A"; } }
class B extends A { function test(){ echo "B"; } }
8. What is Abstraction?
Hiding internal details and showing only functionality using:
- Abstract classes
- Interfaces
9. Difference between Abstract Class and Interface?
| Feature | Abstract Class | Interface |
|---|---|---|
| Methods | Both abstract & normal | Only abstract |
| Properties | Allowed | Not allowed |
| Multiple Inheritance | No | Yes |
10. What are Access Modifiers?
| Modifier | Access |
|---|---|
| public | Everywhere |
| private | Same class |
| protected | Class + child |
🔵 Advanced Questions
11. What is Late Static Binding?
Allows static methods to be resolved based on the called class, not the declaring class.
class A {
public static function test() {
static::who();
}
public static function who() {
echo "A";
}
}class B extends A {
public static function who() {
echo "B";
}
}B::test(); // Output: B
12. What are Magic Methods?
Special methods starting with __
Examples:
__construct()__destruct()__get()__set()__toString()
13. What is Dependency Injection?
Passing dependencies to a class instead of creating inside.
class DB {}
class User {
private $db;
public function __construct(DB $db) {
$this->db = $db;
}
}
14. What is Trait in PHP?
Used to reuse code in multiple classes.
trait Logger {
public function log() {
echo "Logging...";
}
}
15. What is Namespace?
Used to avoid class name conflicts.
namespace App\Models;
class User {}
🔴 Scenario-Based Questions (Very Important 🚀)
16. How would you design a login system using OOP?
- User class
- Auth controller
- Database class
- Password hashing
17. How do you handle database in OOP PHP?
- Use PDO
- Create DB class
- Use Singleton or Dependency Injection
18. What is MVC?
- Model → Data
- View → UI
- Controller → Logic
🎯 Pro Interview Tips
- Always explain with real examples
- Mention security (password_hash, PDO)
- Talk about scalability & clean code
- Avoid procedural style in answers






