psalm
psalm copied to clipboard
Getting MixedArrayAssignment on objects with magic getters and non-string-literal property names.
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.
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