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

UndefinedPropertyFetch should not be emitted when within a property_exists check #5913

Closed
mr-feek opened this issue Jun 9, 2021 · 4 comments
Labels

Comments

@mr-feek
Copy link
Contributor

mr-feek commented Jun 9, 2021

https://psalm.dev/r/7b8648a68c

I assume very related to #4182

@psalm-github-bot
Copy link

I found these snippets:

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

class Foo
{
    public function __construct(array $data)
    {
        foreach ($data as $key => $value) {
            $this->{$key} = $value;
        }
    }
}

$foo = new Foo(['bar' => 'hello']);

if (property_exists($foo, 'bar')) {
    echo $foo->bar;
}
Psalm output (using commit f5bc841):

ERROR: UndefinedPropertyFetch - 16:10 - Instance property Foo::$bar is not defined

INFO: MixedArgument - 16:10 - Argument 1 of echo cannot be mixed, expecting string

INFO: MixedAssignment - 7:35 - Unable to determine the type that $value is being assigned to

@weirdan weirdan added the bug label Jun 10, 2021
@niconoe-
Copy link

Same here, but the weird thing is that methods into method_exists checks are ok.

https://psalm.dev/r/2d09a2b002

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/2d09a2b002
<?php

class A
{
    public function test(array $array): mixed
    {
        if (property_exists($this, 'xProperties')) {
            return $this->xProperties;
        }
        
        if (method_exists($this, 'testing')) {
            return $this->testing($array);
        }
        
        return null;
    }
}
Psalm output (using commit 285fa13):

ERROR: UndefinedThisPropertyFetch - 8:20 - Instance property A::$xProperties is not defined

@orklah
Copy link
Collaborator

orklah commented Oct 24, 2021

duplicate of #2206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants