1.2.351. Different Constructors

PHP allows different signatures for constructors. This is a legacy feature.

Only constructors are allowed to have different signatures : all other methods must be compatible with the parent methods.

<?php

class x {
     function __construct($a) {
     }
}

class y extends x {
     function __construct($a, $b) {
             $this->b = $a;
             parent::__construct($a);
     }
}

?>

1.2.351.1. Suggestions

  • Synchronize the methods signatures

  • Make use of named constructors to have different signatures when building objects

1.2.351.2. Specs

Short name

Classes/IncompatibleConstructor

Rulesets

All, Changed Behavior, Class Review

Exakat since

2.5.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Available in

Entreprise Edition, Exakat Cloud