Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MethodSignatureMismatch - Argument 1 of DateTime::__unserialize has wrong type 'mixed', expecting 'array<array-key, mixed>' as defined by DateTimeInterface::__unserialize #8957

Open
michnovka opened this issue Dec 20, 2022 · 7 comments · Fixed by #8976 · May be fixed by #10131
Labels
easy problems Issues that can be fixed without background knowledge of Psalm good first issue Help wanted internal stubs/callmap

Comments

@michnovka
Copy link
Contributor

Running on PHP 8.2, I have this code:

I cannot reproduce it on psalm.dev, but I assume it has to do with stubs.

<?php

declare(strict_types=1);

namespace App\Extension\Type;

use DateTime as PHPGlobalDateTime;

class DateTime extends PHPGlobalDateTime
{
    public function __toString(): string
    {
        return $this->format('U');
    }
}

Getting:

ERROR: MethodSignatureMismatch - src/Extension/Type/DateTime.php:10:7 - Argument 1 of DateTime::__unserialize has wrong type 'mixed', expecting 'array<array-key, mixed>' as defined by DateTimeInterface::__unserialize (see https://psalm.dev/042)
class DateTime extends PHPGlobalDateTime implements StringableDateTimeInterface

@orklah
Copy link
Collaborator

orklah commented Dec 20, 2022

Can you check if it reproduces if you don't name your class DateTime ?

Also, it seems that your snippet is not complete, it seems it should implement StringableDateTimeInterface too. Can we have the code for that?

@michnovka
Copy link
Contributor Author

michnovka commented Dec 20, 2022

@orklah the StringableDateTimeInterface is irrelevant, I didnt include it in the snippet as I was reproducing the issue without it also.

I renamed the class from DateTime and the issue persist. This is the minimum reproducible example for me on PHP 8.2 and psalm 5.4

<?php

declare(strict_types=1);

namespace App\Extension\Type;

use DateTime;

class DateTime2 extends DateTime
{
    public function __toString(): string
    {
        return $this->format('U');
    }
}

getting:

ERROR: MethodSignatureMismatch - src/Extension/Type/DateTime2.php:9:7 - Argument 1 of DateTime::__unserialize has wrong type 'mixed', expecting 'array<array-key, mixed>' as defined by DateTimeInterface::__unserialize (see https://psalm.dev/042)
class DateTime2 extends DateTime

@orklah
Copy link
Collaborator

orklah commented Dec 21, 2022

Oh, great, in 8.2, both DateTime and DateTimeInterface have a __unserialize method: https://3v4l.org/RtT39#v8.2.0 contrary to what we can find in documentation: https://www.php.net/manual/en/class.datetimeinterface.php

So we're actually missing definitions for it in https://github.com/vimeo/psalm/blob/master/dictionaries/CallMap_82_delta.php

We have an article about editing those files: https://psalm.dev/docs/contributing/editing_callmaps/ Are you up for a PR? :)

@michnovka
Copy link
Contributor Author

@orklah have a look

@KevinMarques
Copy link

KevinMarques commented Jun 16, 2023

I'm still experiencing this issue with PHP 8.2.7 and Psalm 5.12 (also tried master, 5.11, 5.10, 5.9...) with errorLevel 7 or lower and this example:

<?php

declare(strict_types=1);

namespace App\Extension\Type;

use DateTime;

class DateTime2 extends DateTime
{
    public function __toString(): string
    {
        return $this->format('U');
    }
}

Same error:

MethodSignatureMismatch - Argument 1 of DateTime::__unserialize has wrong type 'mixed', expecting 'array<array-key, mixed>' as defined by DateTimeInterface::__unserialize.

@orklah can you reopen this issue and have a look?

@orklah orklah reopened this Jun 16, 2023
@kylekatarnls
Copy link

Sounds like it needs all DateTime, DateTimeImmutable and DateTimeInterface to be set as it's not a "real" interface.

@kylekatarnls kylekatarnls linked a pull request Aug 19, 2023 that will close this issue
@kylekatarnls
Copy link

The error correctly disappear with #10131 with both PHP 8.1 or 8.2 (so does not sound like the definition in CallMap_82_delta is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm good first issue Help wanted internal stubs/callmap
Projects
None yet
4 participants