PHP OOP - Constructor
In PHP (Object-Oriented Programming), a constructor is a special method within a class that is automatically called when an object of that class is created. It's typically used to initialize properties or run setup code.
Syntax:
Example:
Key Points:
-
The constructor method name is
__construct()
. -
It can accept parameters to initialize class properties.
-
It's automatically executed when an object is instantiated.