Reputation: 353
I have a class to manipulate orders. I have created multiple methods for each purpose too. There can be multiple orders to process which is generated from db. Right now, what I am doing is that, loop through each order and create objects with order id as param to constructor.
foreach($order_row as $order_rows)
{
$order_id=$order_rows->order_id ;
$warehouse =new WarehouseManager($order_id);
$warehouse->ProcessWarehouse();
}
Is it okay to loop like this? Is there any better way to handle this?
Upvotes: 2
Views: 89
Reputation: 461
You don't need to create new object for each order. What if there is a huge number of records returned?, You only need to create one object to process an order one by one.
$warehouse = new WarehouseManager();
foreach($order_row as $order_rows)
{
$order_id=$order_rows->order_id ;
$warehouse->setOrder($order_id); // this method should be implemented first
$warehouse->ProcessWarehouse();
}
Upvotes: 2