I assume you mean
__construct. That method is indeed called the constructor, because it is called when the object is constructed.
The point of a constructor is to supply initial values for the fields within the object. Some people do all sort of stuff in constructors like calculations or connecting to a database, but that’s not really good form as that makes the class way harder to test.
Anyway, as a small example:
public function __construct(string $name)
$this->name = $name;
public function getName(): string
Now if you want to create a new instance you could do
new Person('John Doe') which would give you an object with name John Doe. This name cannot be modified later, because the object has not method to change it. Also note that you must pass a name for a Person to be constructed. If you do
new Person() you will get an error because you didn’t supply a name.
This entire principle of having a variable inside a class and making the class fully responsible for it is called encapsulation.