I have 2 classes, 1 being an Item class that holds private variables for the items cost, name etc and another class that I've named Invoice and I created a private array to hold each item that is added to the invoice in.
Invoice constructor:
public function __construct() {
parent::__construct();
$this->itemsToSell = array();
$this->totalSellingCost = 0.0;
$this->totalCost = 0.0;
}
I have a function in place where I am adding an instance of Item into the array like so...
public function addItemToInvoice(ItemModel $item){
$this->itemsToSell[] = $item;
}
However, when I attempt to access this items functions, while doing a for-each loop like so...
public function getInvoiceProfit() : float{
$profit = 0.0;
foreach($this->itemsToSell as $value){
}
return $profit;
}
within the for-each loop I'm unable to access the objects functions, such as this function held in the ItemModel
public function getItemCostToCustomer() : float {
return $this->itemCostToCustomer;
}
meaning in the for-each loop, I'm unable to perform a command such as..
$value->getItemCostToCustomer();
Coming from a Java background, I know I am able to do this as Java can see the $value would be of type Item, but in PHP I'm not sure how to perform the same operation.