1.2.551. Implements Is For Interface¶
With class heritage, implements should be used for interfaces, and extends with classes.
PHP defers the implements check until execution : the code in example does lint, but won,t run.
<?php
class x {
function foo() {}
}
interface y {
function foo();
}
// Use implements with an interface
class z implements y {}
// Implements is for an interface, not a class
class z implements x {}
?>
1.2.551.2. Connex PHP features¶
1.2.551.2.1. Suggestions¶
Create an interface from the class, and use it with the implements keyword
1.2.551.2.2. Specs¶
Short name |
Classes/ImplementIsForInterface |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |