🐘 PHP
Beginner
What is object-oriented programming (OOP) in PHP?
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.
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?