1.2.241. Constructors

This rule marks methods as constructors. In PHP 8.0 and more recent, only the magic method __construct is the constructor. In older versions, the method with the same name than the class was the constructor, although with a lower priority than the magic method.

<?php

class x {
    // Normal constructor
    function __construct() {}
}

class y {
    // Old style constructor, obsolete since PHP 7.1
    function y() {}
}

class z {
    // Normal constructor
    function __construct() {}

    // Old style constructor, but with lower priority
    function z() {}
}

?>

See also Constructors and Destructors.

1.2.241.1. Connex PHP features

1.2.241.1.1. Specs

Short name

Classes/Constructor

Rulesets

All, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Time To Fix

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud