Old Constructors

In PHP 4, the constructor was the method of the same name as the class. They were called during instantiation of an object. In PHP 7, there were replaced with the __construct method, and were used in case of fallback.

Old constructors are also called PHP 4 constructor, as they were used during that time; they are also called eponymous constructors, as they use the same name as the class.

PHP code

<?php

class X {
     function x() {
             print __METHOD__;
     }

     function foo() {
             print __METHOD__;
     }
}

(new x())->foo();
?>

Before

PHP Deprecated:  Methods with the same name as their class will not be constructors in a future version of PHP; x has a deprecated constructor in /codes/OldConstructors.php on line 3

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; x has a deprecated constructor in /codes/OldConstructors.php on line 3
x::xx::foo

After

x::foo

PHP version change

This behavior changed in 8.0