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

Undetected Undefined property #3642

Closed
leighman opened this issue Jun 23, 2020 · 3 comments
Closed

Undetected Undefined property #3642

leighman opened this issue Jun 23, 2020 · 3 comments
Labels

Comments

@leighman
Copy link
Contributor

leighman commented Jun 23, 2020

https://psalm.dev/r/18ed9c0bd0

Line 22 will fail at runtime with Undefined property id

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/18ed9c0bd0
<?php

class Model {}

abstract class Foo
{
    /** @var int */
    public $id;
    
    /** @psalm-return int */
    abstract public function create();
}

class Bar extends Foo
{
    /** @var Model */
    private $model;
    
    public function __construct()
    {
        $this->model = new Model();
        $this->id = $this->model->id;
    }
    
    public function create()
    {
        return 1;
    }
}
Psalm output (using commit 9b86021):

No issues!

@leighman
Copy link
Contributor Author

Seems to only be if a property with the same name as defined in Foo is being accessed on $this->model

@muglug muglug added the bug label Jun 23, 2020
@muglug muglug closed this as completed in f72b609 Jun 23, 2020
@muglug
Copy link
Collaborator

muglug commented Jun 23, 2020

Oof, this is a very good catch, thanks

TysonAndre pushed a commit to TysonAndre/psalm that referenced this issue Jun 24, 2020
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

2 participants