有什么理由让我的 IDE(实际上是 PHPStorm)理解:
$student->setName('Marco');
Run Code Online (Sandbox Code Playgroud)
是否会返回 , 的实例Student而不setName()在子类中重新定义(仅用于添加 PHPDoc 注释)?
class Person
{
private $name;
/**
* @param string $name
* @return Person
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
}
class Student extends Person { }
Run Code Online (Sandbox Code Playgroud)
你必须像这样覆盖你的方法标签作为注释
/**
* @method Student setName($name)
*/
class Student extends Person { }
Run Code Online (Sandbox Code Playgroud)