psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Assigment to private property of current class given child class is broken

Open danog opened this issue 2 years ago • 2 comments

https://psalm.dev/r/afe6df2159

danog avatar Aug 12 '22 09:08 danog

I found these snippets:

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

class a {
    private int $value = 0;
    public function handle(a $v): void {
        if ($v instanceof b) {
            $v->value = 123;
        } else {
            $v->value = 321;
        }
    }
}

class b extends a {}
Psalm output (using commit f315647):

ERROR: UndefinedPropertyAssignment - 7:13 - Instance property b::$value is not defined

psalm-github-bot[bot] avatar Aug 12 '22 09:08 psalm-github-bot[bot]

Ugh, I hate this thing so much I made a plugin to forbid this: https://github.com/orklah/psalm-strict-visibility

But I guess it's a valid issue still

orklah avatar Aug 12 '22 16:08 orklah