1.2.1399. 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() {}
function f() {}
}
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.1399.2. Connex PHP features¶
1.2.1399.2.1. Suggestions¶
Remove the alias
Fix the alias or the origin method name
Switch to insteadof, and avoid as keyword
1.2.1399.2.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 |
Note |
This issue may lint but will not run |
Available in |