相关疑难解决方法(0)

PHPDoc和后期(静态或动态)绑定

大多数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;  }
}
Run Code Online (Sandbox Code Playgroud)

现在我可以使用这样的类:

Textbox::Make()           // <-- late static binding, returns Textbox
   ->WithLabel('foo')     // …
Run Code Online (Sandbox Code Playgroud)

php phpdoc late-binding late-static-binding php-ide

16
推荐指数
3
解决办法
4618
查看次数

标签 统计

late-binding ×1

late-static-binding ×1

php ×1

php-ide ×1

phpdoc ×1