Auto complete for a variable inside a foreach

Songo picture Songo · Mar 11, 2012 · Viewed 7.8k times · Source

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.

Answer

Songo picture Songo · Apr 1, 2012
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.
        }
    }
}