1.2.791. No Constructor In Interface

PHP manual recommends not adding constructors to interfaces.

‘Although they are supported, including constructors in interfaces is strongly discouraged. Doing so significantly reduces the flexibility of the object implementing the interface. Additionally, constructors are not enforced by inheritance rules, which can cause inconsistent and unexpected behavior.’

```

```

<?php

interface with {
    function __construct();
}

?>

See also Object Interfaces.

1.2.791.1. Suggestions

  • Remove the constructor from the interface

1.2.791.2. Specs

Short name

Interfaces/NoConstructorInInterface

Rulesets

All, Class Review, PHP recommendations

Exakat since

2.4.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

interface

Available in

Entreprise Edition, Exakat Cloud