-
Notifications
You must be signed in to change notification settings - Fork 696
Description
Summary
Psalm incorrectly reports an InvalidNamedArgument error when using named arguments for new ReflectionClass(objectOrClass: $foo).
Code sample
Reproducible snippet:
https://psalm.dev/r/d3654927ce
Psalm output:
ERROR: InvalidNamedArgument - 3:35 - Parameter $objectOrClass does not exist on function ReflectionClass::__construct
Additional context
-
PHPStan has no issues with the same code:
https://phpstan.org/r/1f537f1a-cc83-4a5e-881d-b54ab8b56141 -
PHP itself works fine at runtime, even with named argument
objectOrClass:
https://onlinephp.io/c/a51e4 -
Official PHP documentation for
ReflectionClass::__constructclearly defines$objectOrClassas the parameter name:
https://www.php.net/manual/en/class.reflectionclass.php -
Problem in Psalm source:
It looks like the cause is this stub:
https://github.com/vimeo/psalm/blob/6.x/stubs/Reflection.phpstub#L20
where the constructor is defined with a different parameter name or without named argument support.
Expected Behavior
Psalm should allow using objectOrClass as a valid named argument for ReflectionClass::__construct.
Environment
- Psalm version:
6.x - PHP version:
8.2 - Platform: tested on online playground and local.