Skip to content

Unused constant reported although its used inside an Attribute  #7116

@dmaicher

Description

@dmaicher

Bug report

PHPStan reports a private constant as unused although its used inside an attribute on class level.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

#[\Attribute(\Attribute::TARGET_CLASS)]
class Cache
{
	public function __construct(public int $ttl)
	{
	}
}

#[Cache(ttl: self::CACHE_TTL)]
class HelloWorld
{
	private const CACHE_TTL = 60;
}

See https://phpstan.org/r/c8f6c992-6fa5-442e-b704-c6073970e0e7

=> Constant HelloWorld::CACHE_TTL is unused.

Expected output

No error should be reported on PHP 8+

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

This tiny bug aside: PHPStan is a huge benefit to any php codebase 👍 🎉

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions