-
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 DateTimeImmutable::setTimestamp(timestamp: ...).
Code sample
Reproducible snippet:
https://psalm.dev/r/ff20edb0b1
<?php
(new DateTimeImmutable())->setTimestamp(timestamp: 1);Psalm output:
ERROR: InvalidNamedArgument - 3:41 - Parameter $timestamp does not exist on function DateTimeImmutable::setTimestamp
Additional context
-
PHPStan has no issues with the same code:
https://phpstan.org/r/b71ef274-c5ba-4b50-91d6-c3912b4157bd -
PHP itself works fine at runtime, even with named argument
timestamp:
https://onlinephp.io/c/2d921 -
Official PHP documentation for
DateTimeImmutable::setTimestampclearly defines$timestampas the parameter name:
https://www.php.net/manual/en/datetimeimmutable.settimestamp.php -
Problem in Psalm source:
It looks like the cause is this stub:
https://github.com/vimeo/psalm/blob/6.x/stubs/CoreImmutableClasses.phpstub#L94
where parameter is incorrectly named$unixtimestamp.
Expected Behavior
Psalm should allow using timestamp as a valid named argument for DateTimeImmutable::setTimestamp.
Environment
- Psalm version:
6.x - PHP version:
8.2 - Platform: tested on online playground and local.