Answer the question
In order to leave comments, you need to log in
How to define an instance of a class in PHPDoc?
Hello! I use PHPStorm and write PHPDoc style comments:
class User {
static function getWolF() {
$class = 'WolF';
$class = new $class();
return $class;
}
}
class WolF {
public function test($a, $b) {
return $a + $b;
}
}
class Hope {
/**
* @var WolF
*/
protected $j;
public function jaz() {
$this->j = new User();
$this->j = $this->j->getWolF();
$this->j->test();
}
}
$this->j->test();
is highlighted in red (it says that there is no test method). Answer the question
In order to leave comments, you need to log in
I can change everything except the User class.
And, more precisely, there each time a different type is returned.
/**
* @return Wolf
*/
static function getWolF() {
$class = 'WolF';
$class = new $class();
return $class;
}
If the property is not accessed from an object method and, accordingly, the property would be declared as public, then it would be possible to write in the dock for the class
/**
* @property WolF $j
*/
class Hope {
public $j;
...
}
public function jaz() {
$user = new User();
$j = $user->getWolF();
/**
* @var $j WolF
*/
$this->j = $j;
$this->j->test();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question