Skip to content

Constants in return array syntax #5773

@puniserv

Description

@puniserv

Feature request

PHPstan tool is great tool and can be greater with this little feature ;)

https://phpstan.org/r/2cb586a7-3ade-448b-95cb-21641f483a1e

For now class constants are not supported in return array syntax. Maybe this can be changed?

<?php declare(strict_types = 1);

class HelloWorld
{
	public const SOME_KEY = 'key';
	
	/** @return array{HelloWorld::SOME_KEY: int} */
	public function v1(): array
	{
		return [
			self::SOME_KEY => 123,
		];
	}
	
	/** @return array{self::SOME_KEY: int} */
	public function v2(): array
	{
		return [
			self::SOME_KEY => 123,
		];
	}
	
	/** @return array{static::SOME_KEY: int} */
	public function v3(): array
	{
		return [
			static::SOME_KEY => 123,
		];
	}
}

Thank you for this tool, I cannot imagine work without PHPStan anymore ;)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions