Skip to content

Add generic support to @method definitions #6371

@allejo

Description

@allejo

Feature request

Would it be possible to add generic support to functions that are defined via @method docs?

<?php declare(strict_types = 1);

/**
 * @template T
 * @template K
 *
 * @method bool compare<T, K>(T $t, K $k) Compares two objects magically somehow
 * @method bool dumbCompare($t, $k) Compares without generics
 */
class HelloWorld
{
	public function __call(): mixed {
		return true;
	}
}

$h = new HelloWorld();
$h->compare(1, 4);
$h->dumbCompare(5, 3);

https://phpstan.org/r/1da86817-e322-401b-938d-6272e51d85e0

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

Yes! It's helped me a lot with avoiding errors in my projects because I would mess up types. Especially generic support, which is incredibly useful ❤️

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