PHP class refer to second class which refer to first and so on -


sorry question title, don't know how name issue, here is:

i have 2 classes, order , item. order has many itens (array of itens). item refer order (order object).

the problem is: order has itens, each item refer order, wich has itens, wich refer order, wich refer itens, , on...

the array hierarchy gets infinite.

also don't know how construct order object. have create itens , set them order's item array, how can set item's order if order isn't yet constructed?

btw, data comes database. table item has order_id.

nothing fance do, just:

class order {     public $id;     public $item;      public function setitem(item $item)     {         $this->item = $item;     } }  class item {     public $id;     public $order;      public function setorder(order $order)     {         $this->order = $order;     } }  $order = new order(); $item  = new item(); $order->setitem($item); $item->setorder($order); 

php saves references objects, there no endless recursion. converting such data structures json or else, require sort of converter, topic.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -