Methods with the same name as their class will not be constructors in a future version of PHP; %s has a deprecated constructor¶
Description¶
In PHP 4, the constructor of a class was the method with the same name as the class. In the example, the X::X
method is the constructor. This was deprecated in PHP 7.0, in favor of using the __construct
method.
During the deprecation phase, the eponymous method was still used as the constructor, if the __construct
method was not available.
Example¶
<?php
class X {
function X() {}
}
?>
Solutions¶
Rename the eponymous method to
__construct
.Crete the
__construct
method, and make it call the eponymous method.