I have 3 classes like :
class Foo
{
static function test()
{
return new static();
}
}
class Bar extends Foo
{}
class Baz extends Foo
{}
Now if call :
$var = Bar::test();
I want PhpStorm to identify $var
as the called_class
, here: Bar
.
But, if I do $var = Baz::test();
$var
is Baz
instance.
How can I get the dynamic called_class to indicate to PhpStorm what type is returned?
I there a syntax like
/** @return "called_class" */
to help PhpStorm and indicate the type?
First you have an error in your static function. You can not use
as the static call will not create any instance. So you have to create a new instance.
The static keyword will instantiate a new instance of the class itself.
i just added the foo functions to show you that phpStorm now will correctly find the source.
$var is now an instance of Bar
$var2 is now an instance of Baz