Skip to content

Return type of variadic function is not correctly determined #7020

@eliashaeussler

Description

@eliashaeussler

Bug report

First of all, thanks for making my life so much easier with PHPStan! I love it ❤️

My problem is that PHPStan does not seem to correctly determine the return type of my variadic function. According to https://phpstan.org/writing-php-code/phpdocs-basics#variadic-functions, I annotated the parameter type as follows:

/**
 * @param array<int, string> ...$templatePaths
 * @return array<int, string>
 */
public static function merge(array ...$templatePaths): array
{
    $mergedTemplatePaths = array_replace(...$templatePaths);
    ksort($mergedTemplatePaths);

    return $mergedTemplatePaths;
}

But it keeps reporting:

Method TemplatePaths::merge() should return array<int, string> but returns array<int|string, array<int, string>>.

Code snippet that reproduces the problem

https://phpstan.org/r/30d06460-a26c-4383-b1b3-259d8ced39b2

Example: https://3v4l.org/0gZdk

Expected output

From my understanding, there shouldn't be an issue with my annotation as it can be seen in the example. But I must probably mixed something up with the variadics...

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

PHPStan is part of my daily business and it's literally one of the first things I add to each new project 💙. Thanks for all your efforts and constant development!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions