The acronym OOP stands for Object-Oriented Programming. While in procedural programming we write functions that perform operations on data, in OOP we focus on creating objects. These objects combine both data (properties) and functions (methods), which allows for more natural and organized code writing.
If you are wondering why you should switch from regular functions to an object-oriented approach, the list below reveals four key reasons that make daily work with larger and more complex applications easier for modern developers:
The interactive table below will take you through the fundamental pillars of OOP in the PHP language. Each concept contains a brief theoretical description, and by clicking the button, you can open a practical code example to see how theory is turned into a working program:
| Name | Description | Example |
|---|---|---|
Classes |
How to correctly structure a class and its properties. | ▶ Code example |
Objects |
How to create a concrete object from a class and manage it. | ▶ Code example |
Inheritance |
A mechanism where one class inherits the properties and methods of another class. | ▶ Code example |
Constructor |
A special method that prepares an object immediately upon its creation. | ▶ Code example |
Destructor |
A method that cleans up resources when an object is no longer needed or the script ends. | ▶ Code example |
Modifiers |
Determining security: Who can see the data (public, private, protected). | ▶ Code example |
Constants |
Fixed values within classes that do not change during execution. | ▶ Code example |
Polymorphism |
The ability of different classes to respond to the same method call in their own way. | ▶ Code example |
Encapsulation |
Hiding internal operational details from the outside world for increased security. | ▶ Code example |
Namespaces |
Preventing naming conflicts by using logical folders within the code. | ▶ Code example |
Iterable Parameter |
Using the Iterable type to work with data lists in loops. | ▶ Code example |