1.2.574. Inherited Property Type Must Match

Properties that are inherited between classes must match.

This affect public and protected properties. Private properties are immune to this rule, as they actually are distinct properties.

<?php

class A {
    private A $a;
    protected array $b;
    public $c;
}

class B extends A {
    private A $a;       // OK, as it is private
    protected int $b;   // type must match with the previous definition
    public $c;          // no type behaves just like a type : it must match too.
}

?>

See also Properties.

1.2.574.1. Suggestions

  • Remove the definition in the child class

  • Synchronize the definition of the property in the child class

1.2.574.2. Specs

Short name

Classes/InheritedPropertyMustMatch

Rulesets

All, Analyze, Class Review, LintButWontExec

Exakat since

2.2.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

inheritance, property

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud