Skip to content

Bad guess for named params in complex spread call #9559

@rogerespel

Description

@rogerespel

Bug report

I have a function that takes a bunch of named arguments (php 8.0+), and one of its callers uses conditionals to build an array that will be used to call the function.
PHPStan wrongly says "Parameter #1 $z of function foo expects ZZ|null, int|string given.", but the actual code only generates named arguments, there is never a "parameter #1".

Frankly I'm quite amazed that PHPStan gets as far as it does with this, so I'd be ready to just consider it too dynamic for static analysis, stick in a @phpstan-ignore-line and call it a day. For what it's worth, if I remove line 8 (the one with if($x)), PHPStan is actually able to validate the code, which makes me think that it's not far from being able to handle this example.

Code snippet that reproduces the problem

https://phpstan.org/r/4d448372-e178-45cb-a125-284edc0f1911

Expected output

Should not report it a bug, or at least report something more general but accurate, such as "unable to validate parameter names/types in call to function foo".

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

Yes! I've been running it with increasing levels through some 10k lines of fairly modern code, and it has helped me fix a few minor bugs and tighten some interfaces. Thanks :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions