1.2.562. Incompatible Signature Methods

Methods should have the same signature when being overwritten.

The same signatures means the children class must have :

  • the same name

  • the same visibility or less restrictive

  • the same typehint or removed

  • the same default value or removed

  • a reference like its parent

This problem emits a fatal error, for abstract methods, or a warning error, for normal methods. Yet, it is difficult to lint, because classes are often stored in different files. As such, PHP do lint each file independently, as unknown parent classes are not checked if not present. Yet, when executing the code, PHP lint the actual code and may encounter a fatal error.

<?php

class a {
    public function foo($a = 1) {}
}

class ab extends a {
    // foo is overloaded and now includes a default value for $a
    public function foo($a) {}
}

?>

See also Object Inheritance.

1.2.562.1. Suggestions

  • Make signatures compatible again

1.2.562.2. Specs

Short name

Classes/IncompatibleSignature

Rulesets

All, Analyze, LintButWontExec

Exakat since

1.3.3

PHP Version

With PHP 7.4 and older

Severity

Critical

Time To Fix

Quick (30 mins)

Precision

Medium

Examples

SuiteCrm

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud