Cannot use ‘static’ as method modifier

Description

When resolving name conflicts during trait imports, it is not possible to use static with the as keyword. The situation is actually confusing: static 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.

Example

<?php
trait T1 {
     function foo() {}
}
class C1 {
     use T1 {
             T1::foo as static;
     }
}
?>

Solutions

  • Use another name than static for the alias.

  • Use another name than static for the original method.