Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto complete for a variable inside a foreach

I have the following code:

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
        }
    }
}

The problem is easy. I just want to be able to declare a type for my variable $supplier like how I did it with $suppliers.

Notes:

  • Supplier is a class which has a public method getSupplierName().
  • I'm using Netbeans IDE.
like image 458
Songo Avatar asked Mar 11 '12 09:03

Songo


2 Answers

For me this not work:

foreach ($suppliers as /* @var $supplier Supplier */ $supplier) {
    $supplier->/*should have suggestions*/
}

my solution:

foreach ($suppliers as $supplier) {
    if($suppliers instancof Supplier) {
        $supplier->
    }
}
like image 135
Thomas Berg Avatar answered Oct 20 '22 14:10

Thomas Berg


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.
        }
    }
}
like image 27
Songo Avatar answered Oct 20 '22 15:10

Songo