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

UndefinedThisPropertyFetch within property_exists() check #7922

Closed
ghost opened this issue May 3, 2022 · 2 comments
Closed

UndefinedThisPropertyFetch within property_exists() check #7922

ghost opened this issue May 3, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented May 3, 2022

I am loading dynamic objects and testing for some properties via property_exists(). Unfortunately, this causes UndefinedThisPropertyFetch errors.

https://psalm.dev/r/0a435e7d65

I tested the same code with phpstan and it produces no errors.

Seems like this is an old issue: #5913

Thank you.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0a435e7d65
<?php

class A {
    function test(): void
    {
        
        if(property_exists($this, "foo"))
        	echo "$this->foo";
        
    }
}
Psalm output (using commit f960d71):

ERROR: UndefinedThisPropertyFetch - 8:16 - Instance property A::$foo is not defined

@AndrolGenhald
Copy link
Collaborator

I'll close this as a duplicate of #2206, but I hope for this to be possible eventually by intersecting classes with object-with-properties (eg A&object{foo: mixed}) so that property_exists and isset can add properties to an existing class.

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

No branches or pull requests

1 participant