psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Different results between `DateTime` and `DateTimeImmutable`

Open tarlepp opened this issue 4 years ago • 4 comments

I noticed that DateTime and DateTimeImmutable works different way, but those should work as the same.

I first noticed this with PHP 8 named parameters and DateTimeImmutable usage, and I made fix for that part - https://github.com/vimeo/psalm/pull/5218

But now I'm still seeing different handling on DateTime class - and I cannot find the code where that is done.

https://psalm.dev/r/129b9fce2b https://psalm.dev/r/ee31f26136

tarlepp avatar Feb 14 '21 17:02 tarlepp

I found these snippets:

https://psalm.dev/r/129b9fce2b
<?php

new DateTime(timezone: new DateTimeZone('UTC'));
Psalm output (using commit ede9510):

ERROR: InvalidNamedArgument - 3:14 - Parameter $timezone does not exist on function DateTime::__construct

psalm-github-bot[bot] avatar Feb 14 '21 17:02 psalm-github-bot[bot]

There's a bug in the Callmap handling when more than one signature exists and a parameter exists only in the second signature. For example: https://psalm.dev/r/4a288e2401 I guess an easy fix would be to inverse the two signature so that the more complete one is the first...

orklah avatar Oct 12 '21 10:10 orklah

I found these snippets:

https://psalm.dev/r/4a288e2401
<?php

$a = gettimeofday(as_float: true);
/** @psalm-trace $a */
Psalm output (using commit d540320):

ERROR: InvalidNamedArgument - 3:19 - Parameter $as_float does not exist on function gettimeofday

INFO: Trace - 4:23 - $a: float

INFO: UnusedVariable - 3:1 - $a is never referenced or the value is not used

psalm-github-bot[bot] avatar Oct 12 '21 10:10 psalm-github-bot[bot]

@orklah I've tried to only invert the two method but it does not seems to work: https://github.com/vimeo/psalm/pull/8513

I don't know much in psalm internals so it might not be enough.

magnetik avatar Sep 26 '22 08:09 magnetik