Cannot use “abstract” as method modifier in trait alias¶
Description¶
When resolving name conflicts during trait imports, it is not possible to use abstract with the as keyword. The situation is actually confusing: abstract may be the name of the alias, or it could also be understood as the modifier.
The same situation arise with abstract, final or readonly. On the other hand, it is valid to use the visibility modifier to actually change the visibility on the alias.
This message was completed with ‘in trait alias’, in PHP 8.2.
Example¶
<?php
trait T1 {
function foo() {}
}
class C1 {
use T1 {
T1::foo as abstract;
}
}
?>
Solutions¶
Use another name than
abstractfor the alias.Use another name than
abstractfor the original method.