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 when extending ReflectionProperty #7357

Closed
derrabus opened this issue Jan 9, 2022 · 4 comments
Closed

MethodSignatureMismatch when extending ReflectionProperty #7357

derrabus opened this issue Jan 9, 2022 · 4 comments
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue internal stubs/callmap

Comments

@derrabus
Copy link

derrabus commented Jan 9, 2022

ReflectionProperty::setValue() and ReflectionProperty::getValue() are polymorphic. If you work on a static property you can omit the first parameter which is the object on which you want to access the property.

The following code is valid imho:

class MyReflectionProperty extends ReflectionProperty
{
    public function getValue(?object $object = null): mixed
    {
        return parent::getValue(...func_get_args());
    }

    public function setValue(mixed $objectOrValue, mixed $value = null): void
    {
        parent::setValue(...func_get_args());
    }
}

see https://psalm.dev/r/7de1b5f18a and https://3v4l.org/Ie4oo

However, Psalm logs MethodSignatureMismatch errors. If I apply the changes suggested by those errors, I end up with code that would exit with a fatal error:

see https://3v4l.org/mX1AF

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7de1b5f18a
<?php

class MyReflectionProperty extends ReflectionProperty
{
    public function getValue(?object $object = null): mixed
    {
        return parent::getValue(...func_get_args());
    }

    public function setValue(mixed $objectOrValue, mixed $value = null): void
    {
        parent::setValue(...func_get_args());
    }
}
Psalm output (using commit 1a1b5a9):

ERROR: MethodSignatureMismatch - 5:38 - Argument 1 of MyReflectionProperty::getValue has wrong type 'null|object', expecting 'object' as defined by ReflectionProperty::getValue

INFO: MixedArgument - 7:36 - Argument 1 of ReflectionProperty::getValue cannot be mixed, expecting object

ERROR: MethodSignatureMismatch - 10:36 - Argument 1 of MyReflectionProperty::setValue has wrong type 'mixed', expecting 'null|object' as defined by ReflectionProperty::setValue

@orklah
Copy link
Collaborator

orklah commented Jan 15, 2022

Yeah, that seem correct. Would you mind pushing a PR that changes the callmap on that regard?

Thanks

@derrabus
Copy link
Author

I gave it a try: #7402

@weirdan
Copy link
Collaborator

weirdan commented Feb 15, 2023

The original snippet no longer results in MethodSignatureMismatch, so I think it's solved now.

@weirdan weirdan closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue internal stubs/callmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants