psalm
                                
                                
                                
                                    psalm copied to clipboard
                            
                            
                            
                        Different results between `DateTime` and `DateTimeImmutable`
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
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
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...
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
@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.