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

Importing a trait and changing visibility is ignored #4516

Closed
ruudk opened this issue Feb 10, 2021 · 7 comments
Closed

Importing a trait and changing visibility is ignored #4516

ruudk opened this issue Feb 10, 2021 · 7 comments
Labels

Comments

@ruudk
Copy link
Contributor

ruudk commented Feb 10, 2021

Bug report

<?php declare(strict_types = 1);

interface RecordsMessages
{
    public function record(object $message): void;
}

trait PrivateMessageRecorderCapabilities
{
    protected function record(object $message): void
    {
    }
}

class PublicMessageRecorder implements RecordsMessages
{
    use PrivateMessageRecorderCapabilities { record as public; }
}

$recorder = new PublicMessageRecorder();
$recorder->record(new DateTime());

PHPStan reports an issue:

Protected method PublicMessageRecorder::record() overriding public method RecordsMessages::record() should also be public.

While this is allowed by PHP, see: https://3v4l.org/J3ged

Code snippet that reproduces the problem

https://phpstan.org/r/03b14d64-3e97-49bd-a994-3c22570ebde3

Expected output

No errors because this is allowed by PHP, see: https://3v4l.org/J3ged

@ondrejmirtes
Copy link
Member

Related: #3465

@ondrejmirtes ondrejmirtes added this to the Static reflection milestone Feb 10, 2021
@ruudk
Copy link
Contributor Author

ruudk commented Feb 10, 2021

It's also impossible to ignore this error via baseline or ignoredErrors.

ruudk added a commit to SimpleBus/SimpleBus that referenced this issue Feb 10, 2021
@ondrejmirtes
Copy link
Member

Yeah, that's because when this problem is reported (when it's a real problem), it leads to PHP fatal error, so it makes sense it cannot be baselined.

@ondrejmirtes
Copy link
Member

I guess you need to use excludePaths for this file right now.

@ruudk
Copy link
Contributor Author

ruudk commented Feb 10, 2021

That works. Thanks!

ruudk added a commit to SimpleBus/SimpleBus that referenced this issue Feb 10, 2021
ruudk added a commit to SimpleBus/SimpleBus that referenced this issue Feb 11, 2021
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@c524c4e

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants