Skip to content

Changing trait provided final protected method to private results in warning #17214

Closed

Description

@cs278

Description

The following code:

<?php

trait MyTrait
{
    final protected function someMethod(): void {}
}

class Test
{
    use MyTrait {
        someMethod as private anotherMethod;
    }
    
    public function __construct()
    {
        $this->anotherMethod();
    }
}

Resulted in this output:

Warning: Private methods cannot be final as they are never overridden by other classes in /in/YtW3h on line 8

But I expected this output instead:

No error

https://3v4l.org/YtW3h

PHP Version

8.3.14 and 8.4.1

Operating System

No response

Activity

  1. iluuu1994 commented on Dec 18, 2024

    @iluuu1994
    Member

    Not sure I would classify this as a bug, but it makes sense to relax this warning. To clarify, the final modifier is still inherited. /cc @nielsdos, since you implemented GH-13179. Would you agree?

  2. ndossche commented on Dec 18, 2024

    @ndossche
    Member

    Yeah I think I agree

  3. ndossche commented on Dec 19, 2024

    @ndossche
    Member

    When looking at the code that generates the warning, I don't see how the warning can be relaxed. Relaxing would be equivalent to dropping it I think.

  4. added a commit that references this issue on Jan 6, 2025
    39bbc16
  5. added a commit that references this issue on Jan 13, 2025
    a6a290d
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