1.2.799. 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.799.1. Connex PHP features¶
1.2.799.1.1. Suggestions¶
Remove the constructor from the interface
1.2.799.1.2. Specs¶
Short name |
Interfaces/NoConstructorInInterface |
Rulesets |
|
Exakat since |
2.4.0 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |