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

Relax final+private warning for trait methods with inherited final #17381

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from

Conversation

iluuu1994
Copy link
Member

Fixes GH-17214

Small note: I thought we'd have to support as final private, which would not work with this approach. But then noticed that strangely the grammar only allows for a single modifier for the trait alias. Thus, we luckily don't need to handle the case where both final and the visibility can change.

@nielsdos
Copy link
Member

nielsdos commented Jan 6, 2025

Right, so now only this situation creates the warning (if it hadn't already warned earlier):

<?php

trait MyTrait {
    private function someMethod(): void {}
}

class Test {
    use MyTrait {
        someMethod as final anotherMethod;
    }
}

Note though that relaxing the warning might go against the copy+paste behaviour that traits try to mimick, as copy pasting with the editing visibility would generate a warning too. This was the point of introducing the warning. Anyway, I'm not really objecting.

@iluuu1994
Copy link
Member Author

Note though that relaxing the warning might go against the copy+paste behaviour that traits try to mimick

That's a fair pair point. I think this is slightly different in that it the method isn't just copy&pasted, but also modified. Since we don't allow removing modifiers, it seems relaxing this warning would enable a reasonable use-case that worked previously, when you cannot remove final on the trait itself.

@nielsdos
Copy link
Member

nielsdos commented Jan 7, 2025

I guess it's a matter of perspective, I don't object.

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

Successfully merging this pull request may close these issues.

2 participants