1.2.546. 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.546.1. Suggestions

  • Create an interface from the class, and use it with the implements keyword

1.2.546.2. Specs

Short name

Classes/ImplementIsForInterface

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

implements, interface

Available in

Entreprise Edition, Exakat Cloud