1.2.1392. Useless Constructor¶
Class constructor that have empty bodies are useless. They may be removed, as they are not called.
One edge case is when the class has a parent, and the parent constructor must not be called.
Another edge case is promoted properties: the body of the constructor is still empty, but the parameters hold the definitions of properties. These might be better outside the constructor though.
<?php
class X {
function __construct() {
// Do nothing
}
}
class Y extends X {
// Useful constructor, as it prevents usage of the parent
function __construct() {
// Do nothing
}
}
?>
1.2.1392.2. Connex PHP features¶
1.2.1392.2.1. Suggestions¶
Remove the constructor
1.2.1392.2.2. Specs¶
Short name |
Classes/UselessConstructor |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
High |
Available in |