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:
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->
}
}
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.
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With