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 despite property_exists() check #4182

Open
caugner opened this issue Sep 14, 2020 · 13 comments
Open

UndefinedThisPropertyFetch despite property_exists() check #4182

caugner opened this issue Sep 14, 2020 · 13 comments

Comments

@caugner
Copy link
Contributor

caugner commented Sep 14, 2020

https://psalm.dev/r/6cfebb5320

Shouldn't the property_exists() check have the same effect as isset()?

https://psalm.dev/r/58bb4ad896

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/6cfebb5320
<?php

abstract class Base
{
    public function getId(): mixed
    {
        if (!property_exists($this, 'id')) {
            throw new \Exception("Missing id property.");
        }
        
        return $this->id;
    }
}
Psalm output (using commit 77e84b3):

ERROR: UndefinedThisPropertyFetch - 11:16 - Instance property Base::$id is not defined
https://psalm.dev/r/58bb4ad896
<?php

abstract class Base
{
    public function getId(): mixed
    {
        if (isset($this->id)) {
            throw new \Exception("Missing id property.");
        }
        
        return $this->id;
    }
}
Psalm output (using commit 77e84b3):

No issues!

@caugner
Copy link
Contributor Author

caugner commented Sep 14, 2020

Sorry, it should be !isset instead of isset:

https://psalm.dev/r/1b76e227ca

Weirdly Psalm does NOT emit the UndefinedThisPropertyFetch after the isset, even though the property id most likely does NOT exist after the isset check.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/1b76e227ca
<?php

abstract class Base
{
    public function getId(): mixed
    {
        if (!isset($this->id)) {
            throw new \Exception("Missing id property.");
        }
        
        return $this->id;
    }
}
Psalm output (using commit 77e84b3):

No issues!

@orklah
Copy link
Collaborator

orklah commented Oct 24, 2021

duplicate of #2206

@orklah orklah closed this as completed Oct 24, 2021
@AndrolGenhald
Copy link
Collaborator

Reopening for https://psalm.dev/r/58bb4ad896 which is distinct from #2206.

@AndrolGenhald AndrolGenhald reopened this Feb 18, 2022
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/58bb4ad896
<?php

abstract class Base
{
    public function getId(): mixed
    {
        if (isset($this->id)) {
            throw new \Exception("Missing id property.");
        }
        
        return $this->id;
    }
}
Psalm output (using commit 97bd81c):

No issues!

@gndk
Copy link
Contributor

gndk commented Sep 13, 2022

This should not happen:
https://psalm.dev/r/d206ded407

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/d206ded407
<?php

class Stuff
{
}

$value = new Stuff();

if (property_exists($value, 'nonExistingProperty')) {
    if ($value->nonExistingProperty === 'someValue') {
        return;
    }
}
Psalm output (using commit d957ff2):

ERROR: UndefinedPropertyFetch - 10:9 - Instance property Stuff::$nonExistingProperty is not defined

@weirdan
Copy link
Collaborator

weirdan commented Nov 24, 2022

This now works: https://psalm.dev/r/58bb4ad896

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/58bb4ad896
<?php

abstract class Base
{
    public function getId(): mixed
    {
        if (isset($this->id)) {
            throw new \Exception("Missing id property.");
        }
        
        return $this->id;
    }
}
Psalm output (using commit 8f39de9):

No issues!

@orklah
Copy link
Collaborator

orklah commented Nov 24, 2022

Closing this then. #2206 will track the property_exists issue

@orklah orklah closed this as completed Nov 24, 2022
@AndrolGenhald
Copy link
Collaborator

Actually still broken. It should be a !isset() not isset(), and Psalm doesn't catch it.

https://psalm.dev/r/58bb4ad896

@AndrolGenhald AndrolGenhald reopened this Nov 24, 2022
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/58bb4ad896
<?php

abstract class Base
{
    public function getId(): mixed
    {
        if (isset($this->id)) {
            throw new \Exception("Missing id property.");
        }
        
        return $this->id;
    }
}
Psalm output (using commit 8f39de9):

No issues!

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

No branches or pull requests

5 participants