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! :)