TraitsPropertiesConflicts
error on by defaultGroup: Probable bugs · PhpStorm name: TraitsPropertiesConflictsInspection
When a class and one of its traits (or its parent class and one of its traits) declare the same property, PHP only accepts it if both declarations are compatible, and even then the duplication is fragile. Point out these overlaps; when the two declarations are incompatible (PHP refuses to compose the class), it is a real conflict.
Example
php
<?php
trait HasColor {
public $color = 'red';
protected $shade = 1;
}
trait HasSize {
public $size = 10;
private $unit = 'px';
}
/**
* @property $note
*/
trait HasMeta {
/** @Column */
public $tag = 'x';
public $label = 'L';
protected $weight = 2;
}
class Shape {
public $color = 'red';
protected $size = 12;
private $unit = 'em';
}
/**
* @property $weight
*/
class Box extends Shape {
use HasColor, HasSize;
use HasMeta;
/** @Column */
public $tag = 'x';
public $label = 'L';
protected $weight = 3;
public $note = 'n';
}Reported:
- line 31: Box and trait HasColor both declare property $color.
- line 31: Box and trait HasSize both declare property $size.
- line 36: Box and trait HasMeta both declare property $label.
- line 37: Box and trait HasMeta both declare property $weight.
Configure
In custos.json:
json
{
"rules": {
"TraitsPropertiesConflicts": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore TraitsPropertiesConflicts
/**
* @noinspection TraitsPropertiesConflictsInspection
*/