Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cs278 opened this issue Dec 18, 2024 · 2 comments
Open

Comments

@cs278
Copy link

cs278 commented Dec 18, 2024

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

@iluuu1994
Copy link
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?

@nielsdos
Copy link
Member

Yeah I think I agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants