Cannot use ‘final’ as method modifier

Description

When resolving name conflicts during trait imports, it is not possible to use final with the as keyword. The situation is actually confusing: final may be the name of the alias, or it could also be understood as the modifier.

The same situation arise with abstract, static 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 final;
     }
}
?>

Solutions

  • Use another name than final for the alias.

  • Use another name than final for the original method.