PHP

Basic class definitions begin with the keyword class.
02.01.2022
img

Class − This is a programmer-defined data type, which includes local functions as well as local data. You can think of a class as a template for making many instances of the same kind (or class) of object.

OOP Case
Let's assume we have a class named Simple. A Simple can have properties like id, age, name, . We can define variables like $id, $age, $name to hold the values of these properties.
When the individual objects (object1, object2, etc.) are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties.

The __construct Function
A constructor allows us to initialize an object's properties upon creation of the object.
If you create a __construct() function, PHP will automatically call this function when you create an object from a class.Notice that the construct function starts with two underscores ( __ )!

back to all posts