自动完成foreach中的变量

Son*_*ngo 9 php foreach netbeans autocomplete phpdoc

我有以下代码:

class Orders{
    /**
     *
     * @var Supplier
     */
    private $suppliers; //Array of Supplier

    function loopAllSuppliers(){
        foreach($this->suppliers as $supplier){
            $supplier->/*no suggestion*/ //Can't get the method's to show here

            $this->suppliers->getSupplierName(); //methods in class Supplier show normally here
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题很简单.我只是想能够为我的变量声明一个类型,$supplier就像我用它做的那样$suppliers.

笔记:

  • Supplier是一个具有公共方法getSupplierName()的类.
  • 我正在使用Netbeans IDE.

Son*_*ngo 18

class Orders{
    /**
     *
     * @var Supplier
     */
    private $suppliers;

    function loopAllSuppliers(){
        foreach($this->suppliers as $supplier){ /* @var $supplier Supplier */
      //Must declare the type again inside the foreach as Netbeans doesn't support
      // defining variable as arrays in doc blocks, yet.
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 为什么不只是`foreach($ this->供应商/*@var供应商*/$供应商)` (2认同)