Skip to content

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

@Ilyes512

Description

@Ilyes512

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions