psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Getting MixedArrayAssignment on objects with magic getters and non-string-literal property names.

Open rzvc opened this issue 10 months ago • 1 comments

https://psalm.dev/r/9031678695

The code above shows the issue. What's interesting is that it only appears if $name is a string not a literal-string, so removing its type specifier and assigning it to an arbitrary string, will remove the error.

rzvc avatar Mar 28 '24 04:03 rzvc

I found these snippets:

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

/**
 * @template T
*/
class Foo
{
    /** @return T */
	public function & __get(string $name)
	{
		return null;
	}
}

/** @var Foo<list<int>> */
$test = new Foo();

/** @var string */
$name = null;

$test->$name[] = 1;
Psalm output (using commit ef3b018):

INFO: MixedArrayAssignment - 21:1 - Cannot access array value on mixed variable 

psalm-github-bot[bot] avatar Mar 28 '24 04:03 psalm-github-bot[bot]