1.2.676. Method Collision Traits

Two or more traits are included in the same class, and they have methods collisions.

Those collisions should be solved with a use expression. When they are not, PHP stops execution with a fatal error : Trait method M has not been applied, because there are collisions with other trait methods on C.

The code shown lints, but doesn’t execute.

<?php

trait A {
    public function A() {}
    public function M() {}
}

trait B {
    public function B() {}
    public function M() {}
}

class C {
    use  A, B;
}

class D {
    use  A, B{
        B::M insteadof A;
    };
}

?>

See also Traits.

1.2.676.2. Connex PHP features

1.2.676.2.1. Specs

Short name

Traits/MethodCollisionTraits

Rulesets

All, Analyze, Changed Behavior, LintButWontExec

Exakat since

1.4.2

PHP Version

All

Severity

Critical

Time To Fix

Quick (30 mins)

Precision

High

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud