PHP 7 – PHP 4-Style Constructors are Deprecated

PHP 4 constructors were preserved in PHP 5 alongside the new __construct().PHP 4 constructors are methods that have the same name as the class they are defined in. Now, PHP 4-style constructors are being deprecated in favour of having only a single method (__construct()) to be invoked on object creation. And in PHP8 recognition for old constructors will be outright removed so it’s better to avoid PHP 4 style constructors.

Before PHP 5 and PHP 5 – class is defined within a namespace or if an __construct() method existed, then a PHP 4-style constructor was recognized as a plain method. If it was defined above an __construct() method, then an E_STRICT notice would be emitted, but still recognized as a plain method.

In PHP 7, if the class is not in a namespace and there is no __construct() method present, the PHP 4-style constructor will be used as a constructor but an E_DEPRECATED will be emitted.

In PHP 8, the PHP 4-style constructor will always be recognized as a plain method and the E_DEPRECATED notice will disappear.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.