Skip to content

2.1.18 __invoke return type not recognized depending on how the class is resolved #13296

@AJenbo

Description

@AJenbo

Bug report

Sorry if I'm filing this in the wrong project, but it's a bit ambiguous what's causing the issue.

Since PHPStan 2.1.18 the following code will fail (regardless of Larastan or Laravel version).

class Test
{
    public function __invoke(string $entrypoints): HtmlString
    {
        return new HtmlString($entrypoints);
    }
}

\PHPStan\dumpType(app(Test::class)('')); // Dumped type: *ERROR*
\PHPStan\dumpType(app()->make(Test::class)('')); // Dumped type: Illuminate\Support\HtmlString  

What's really strange is that it will still work if we just stick the class instance in a variable first:

$a = app(Test::class);
\PHPStan\dumpType($a('')); // Dumped type: Illuminate\Support\HtmlString  
$b = app()->make(Test::class);
\PHPStan\dumpType($b('')); // Dumped type: Illuminate\Support\HtmlString  

app() is a Laravel helper and it's return value is being resolved by Larastan.

Code snippet that reproduces the problem

No response

Expected output

Dumped type: Illuminate\Support\HtmlString

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions