Why does this work:
/* @var $foo ClassName */
$foo->someFunction();
but this one not:
/* @var $this->foo ClassName */
$this->foo->someFunction();
Here's the complete setup:
abstract class Bar
{
$foo = null;
}
class Cool
{
// some function sets $this->foo
public function doSthWithFoo() // does not work
{
/* @var $this->foo ClassName */
$this->foo->someFunction();
}
public function doSthWithFoo2() // works just fine
{
$test = $this->foo
/* @var $test ClassName */
$test->someFunction();
}
}
Another approach would be to define the $foo variable in the new class again:
class Cool
{
/* @var $foo ClassName */
$foo = null;
// ...
}
Of cource the PHP code is executed properly, but the PHPDoc is buggy.
(PhpStorm 2018.2.2)
Thanks in advance!
@var-- only top level/whole entity. So it's what Dale have said .. or you can try@propertytag in yourCoolclass. - LazyOne$fooproperty has no type until a class inherits it and sets its specific type. The intention is to 'force' using the inherited$fooproperty instead of creating lots of different properties... (but as you said that's beyond this question) @LazyOne: You're right, PHPDoc is not buggy, but it would be kind of awesome if that worked. - Flo Bayer