0

I know this is similar to my last question PHP Static vs Instance

But I didn't want to add it there and confuse that question, I believe it does stand on its own merits as a question

I have three classes Billing Invoice InvoiceItem

The billing class works out the billing and finishes up with the data for the invoice and and array of data from the invoice items $billing and $billingItems

the questions is how do I call the methods needed

In Billing Class

$invoice = new Invoice();
$invoice->createFomBilling($billing, $billingItems);

Do I:

1.

In Invoice Class

public function createFomBilling($billing, $billingItems)
{
    foreach($billingItems as $billingItem)
    {
        $item = new InvoiceItems();
        $item->setDataFromBilling($billingItem);
    }
 }

In InvoiceItem Class

public function setDataFromBilling($billingItem)
{
    $this->item1 = $billingItem->item1;
    $this->item2 = $billingItem->item2;
    $this->item3 = $billingItem->item3;
    $this->item4 = $billingItem->item4;
    $this->item5 = $billingItem->item5;
    $this->save();
 }

OR

2.

In Invoice Class

public function createFomBilling($billing, $billingItems)
{
    foreach($billingItems as $billingItem)
    {
        $item = new InvoiceItems();
        $item->item1 = $billingItem->item1;
        $item->item2 = $billingItem->item2;
        $item->item3 = $billingItem->item3;
        $item->item4 = $billingItem->item4;
        $item->item5 = $billingItem->item5;
        $item->save();
    }
 }

this way i do it all in the invoice class and i dont write code in the invoiceItem class

Any ideas

3
  • 1
    hahhaaha....i am confused whether you are giving an answer or asking a question :-p Commented Nov 28, 2013 at 11:24
  • 1
    lol, sorry, i am asking a question, I really just asking if i should keep the code in the calss that i am using i.e. invoice in Invoice and invoiceItems in InvoiceItems and put all methods there Commented Nov 28, 2013 at 11:46
  • Try to write methods with within classes. Commented Nov 29, 2013 at 4:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.