phpstan: PHPDoc block is ignored for closures/anonymous functions

Bug report

spl_autoload_register(
    /**
     * @param class-string $class_name The fully-qualified class name.
     * @return void
     */
    static function ($class_name) {
Parameter #1 $autoload_function of function spl_autoload_register expects callable(string): void, Closure(mixed): mixed given.

Code snippet that reproduces the problem

https://phpstan.org/r/56909d36-0d70-4c8d-990a-be01e822c572

Expected output

No error.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 11
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

This feature isn’t hard but there’s quite a few places we need to think of. I made a list of points that we need to keep track of during development:

The extra features mentioned in the list subitems should probably be turned off when PHPDoc is present.

Additionally, there should be new rules:

  • Similar rule to IncompatiblePhpDocTypeRule - about nonexistent parameter names, about incompatible types like string in @param but for native type int etc.
  • Similar rule to InvalidPhpDocTagValueRule for PHPDoc parse errors
  • FunctionDefinitionCheck::checkAnonymousFunction also needs to be updated to read the PHPDocs
  • We also need to make sure that generics work and add a rule for that like FunctionTemplateTypeRule.

This should be done over multiple small PRs which is the way I like to work.

I also offer to implement this for a fee paid against an invoice I’d issue. My estimate as what this would cost to have this developed by myself is 1500-2000 EUR. Feel free to reach out if you’re interested 😃