1.2.1389. Useless Method Alias

It is not possible to declare an alias of a method with the same name.

PHP reports that Trait method f has not been applied, because there are collisions with other trait methods on x, which is a way to say that the alias will be in conflict with the method name.

When the method is the only one bearing a name, and being imported, there is no need to alias it. When the method is imported in several traits, the keyword insteadof is available to solve the conflict.

This code lints but doesn’t execute.

<?php

trait t {
    function h() {}
}

class x {
    use t {
        // This is possible
        t::f as g;

        // This is not possible, as the alias is in conflict with itself
        // alias are case insensitive
        t::f as f;
    }
}

?>

See also Conflict resolution.

1.2.1389.1. Suggestions

  • Remove the alias

  • Fix the alias or the origin method name

  • Switch to insteadof, and avoid as keyword

1.2.1389.2. Specs

Short name

Traits/UselessAlias

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior, LintButWontExec

Exakat since

1.5.6

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Features

trait

Note

This issue may lint but will not run

Available in

Entreprise Edition, Community Edition, Exakat Cloud