大多数
PHP IDE依靠phpdoc来获取关于表达式类型的提示.然而,我经常使用这种模式,似乎没有涵盖:
class Control { private $label = ''; /** @return ??? */ public static function Make(){ return new static(); } /** @return ??? */ public function WithLabel($value){ $this->label = $value; return $this; } /** @return void */ public function Render(){ /* ... */ } } class Textbox extends Control { private $text = ''; /** @return ??? */ public function WithText($text){ $this->width = $text; return $this; } }
现在我可以使用这样的类:
Textbox::Make() // <-- late static binding,returns Textbox ->WithLabel('foo') // <-- late dynamic binding,returns Textbox ->WithText('bar') // <-- normal binding,returns Textbox ->Render();
有什么办法用某些东西替换“???”,以便打字信息正确吗?
/** @return Control */
非静态:
/** @return $this */
但是没有在phpdoc手册中记录