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

Incorrect unused reporting on private class const when called using $this::PRIVATE syntax #6758

Closed
Ilyes512 opened this issue Mar 7, 2022 · 1 comment · Fixed by phpstan/phpstan-src#1059
Labels
Milestone

Comments

@Ilyes512
Copy link

Ilyes512 commented Mar 7, 2022

Bug report

PHPStan reports that an class constant is not being used when the const visibility is private and called using $this. It's does not report it when the visibility of the const is protected or public.

Code snippet that reproduces the problem

https://phpstan.org/r/0714e467-bb1f-48a1-8c29-25b30cc47666

<?php declare(strict_types = 1);

use Closure;

class HelloWorld
{
	private const HELLO = 'Hi';
	protected const HELLO2 = 'Hi2';
	
	
	public function speak(): string
	{
		return $this::HELLO;
	}
	
	public function speak2(): string
	{
		return $this::HELLO2;
	}
}

Expected output

No reporting. It currently returns:

Line Error
7 Constant HelloWorld::HELLO is unused.

Did PHPStan help you today? Did it make you happy in any way?

Yup, PHPStan is awesome! Keep up to good work! :)

@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 Apr 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants