1.2.561. Incompatible Property Between Class And Trait

Reports a property definition that doesn’t fit the importing class. The property definition should be identical in the trait and in the class.

<?php

trait t {
     private Invalid $property1;

     private Valid $property2;
}

class xt {
     use t;

     // This is incompatible with the trait
     private OtherType $property1;

     // This is compatible with the trait
     private Valid $property2;
}

?>

1.2.561.1. Suggestions

  • Make sure the property is defined identically in the class and the trait.

  • Change the property definition in the class and make it distinct with the one in the trait.

  • Change the property definition in the trait and make it distinct with the one in the class.

1.2.561.2. Specs

Short name

Traits/IncompatibleProperty

Rulesets

All, Changed Behavior, Class Review

Exakat since

2.5.3

PHP Version

All

Severity

Major

Time To Fix

Slow (1 hour)

Precision

High

Available in

Entreprise Edition, Exakat Cloud