One of the most interesting features that I like about classes is encapsulation . You can encapsulate various chains of functions into one important function and call them directly. Encapsulation creates an environment in which you can protect member objects and properties from changes outside the class.
Another important part of classes is groups . To be able to group all the functions and attributes associated with a particular object in one, and the ability to create different instances of these classes as objects, is simply magical. Let's say you have a bunch of functions that reference each other and pass roughly the same arguments. This is a good sign that these functions belong to the class, and these arguments must be members of the class.
Since you are using PHP, imagine that you created a class that creates a panel. Now you can use this class and create different but similar layouts, such as the news panel, ad panel, product display panel, creating various objects and providing content.
You could say that this is also possible with functions, but functions cannot provide the scalability and flexibility provided by the class.
Inheritance
This is one of the main features of OOP; you can create parent and child classes at an infinite level. For example, you created a class car . This class has attributes such as wheels, gears, steering, such as drive (), stop (), but you cannot accompany all the cars in this world, so now you will create your child class. In this case, the child classes can be 2WD and 4WD, and again these child classes can also have other child classes with new members and methods. But you can access members and functions up to your parents and great parents.
Polymorphism
This means that you can override a function in parent classes. that is, the simple car control system is different from that of the 4WD car drive system, so you need to redefine the previous parent function and replace it with a new function.
Another is Overloading, its ability to be able to use a function in different cases. For example, for a simple car for driving, it requires starting the engine, mechanism and acceleration, but for modern cars, such as a Ferrari, you only need to start the engine and press the accelerator, you do not need gear, so for these two cases itβs ok to use the drive method () you provide different parameters. And classes make this possible (but this function is not available in PHP :()