Utilizor
Contact Us

PHP Constructor

The __construct function.

PHP - The __construct Function

A constructor allows you 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 (__)!

PHP 8 Constructor Promotion

In PHP 8, you can simplify property declaration and assignment by declaring properties in the constructor arguments directly.