Skip to content

Allow "final" modifier when importing a method from a trait  #11388

Closed

Description

@nicolas-grekas

Description

Not sure why this is not allowed currently, but it'd be nice allowing it if there aren't any blockers:

trait SomeTrait {
    function someMethod() {}
}

class SomeClass {
    use SomeTrait {
        someMethod as final;
    }
}

This currently produces: "Cannot use 'final' as method modifier"

Activity

  1. ndossche commented on Jun 7, 2023

    @ndossche
    Member

    Following https://wiki.php.net/rfc/horizontalreuse (which introduced traits), this should be allowed.
    The implementation was refactored in 3f8c729. That commit is the first time the "final" check appears AFAICT, but no reason was given for why. That commit seems to have landed in 5.4.11 and the NEWS for that version doesn't seem to mention something relevant to the behaviour change. I'll check what happens if we remove the check.

  2. added a commit that references this issue on Jun 7, 2023
    79d024a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions