1.2.692. Mismatch Properties Typehints

Properties must match within the same family.

When a property is declared both in a parent class, and a child class, they must have the same type. The same type includes a possible null value.

This doesn’t apply to private properties, which are only visible locally. This code will lint, but not execute.

<?php

// property $p is declared as an object of type a
class x {
    protected A $p;
}

// property $p is declared again, this time without a type
class a extends x {
    protected $p;
}
?>

1.2.692.1. Suggestions

  • Remove some of the property declarations, and only keep it in the highest ranking parent

  • Match the typehints of the property declarations

  • Make the properties private

  • Remove the child class (or the parent class)

1.2.692.2. Specs

Short name

Classes/MismatchProperties

Rulesets

All, Analyze, Class Review, LintButWontExec

Exakat since

2.1.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

property

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud