persistant object array?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
torpedo51
Forum Newbie
Posts: 3
Joined: Thu Mar 13, 2003 2:11 am
Location: Surf City, CA

persistant object array?

Post by torpedo51 »

I could use a little more confidence about this subject before I go build my project.

I think a big advantage to using classes is to be able to structure your data logically in such a way that you can manipulate the data with ease - specifically I want to pass an object to a new page, rather than pass the 50 attributes individually. Furthermore, I'd like to make an array of the objects, and just pass the array.

Can I create an array of objects, and then store them in a single session variable? Then I can retrieve my array of objects from any pages, rather than make a trip to the db to load everything again?

If so, how does this look:

require_once('classdefs.php');
$car[1] = new clsAuto('vw', '337', '2002');
$car[2] = new clsAuto('vw', 'gti', '2003');
$fleet[1] = new clsAutoCollection();
$fleet[1]->addAuto(car[1]);
$fleet[1]->addAuto(car[2]);
$_SESSION['gfleet'] = $fleet;

I'm not concerned about the exact syntax; I just want to know if the concept will work. Thx.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply