Search code examples
phpoopzen-cart

OOP - creating objects - how long does an object last?


I'm trying to modify a shopping cart (zencart) to do what I want, so I've been looking through the code trying to figure things out, but I've come into a mental hurdle.

What I want to do is modify the category navigation sidebox. How it works is that it creates an object to represent the category tree - ie:

$main_category_tree = new category_tree;
$box_categories_array = $main_category_tree->zen_category_tree();

The zen_category_tree function creates the array representing the categories plus subcategories (the id's for which may have been passed via GET)

What I don't understand is that every page has this sidebox, which means every page that loads must create a new category_tree object. Does that seem right? Everything I've read about objects makes it sound like they are persistent things which you wouldn't be creating every-time the sidebox loads?

Confused...


Solution

  • Objects are only persistent during a single HTTP request. On each page load, everything is reset and needs to be recreated again.