psalm
psalm copied to clipboard
When a (typed or not) constant is used on object, the type is lost
When a (typed or not) constant is used on object ($object::CONST
), the type is lost:
class Foo
{
public const string TYPED = 'string';
public const NOTYPE = 'string';
}
works, no error:
func(Foo::TYPED);
func(Foo::NOTYPE);
both throw "Argument 1 of func cannot be mixed, expecting string":
func((new Foo)::TYPED);
func((new Foo)::NOTYPE);
https://psalm.dev/r/0a3523524e
May be loosely related to #10700
I found these snippets:
https://psalm.dev/r/0a3523524e
<?php
class Foo
{
public const string TYPED = 'string';
public const NOTYPE = 'string';
}
function func(string $param): void { echo $param; }
func(Foo::TYPED);
func((new Foo)::TYPED);
func(Foo::NOTYPE);
func((new Foo)::NOTYPE);
Psalm output (using commit ef3b018):
INFO: MixedArgument - 11:6 - Argument 1 of func cannot be mixed, expecting string
INFO: MixedArgument - 13:6 - Argument 1 of func cannot be mixed, expecting string