Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linked Lists and Object Classes

Status
Not open for further replies.

kasuals

Programmer
Apr 28, 2002
100
US
I am trying to keep track of each page in a history so that the user can go back as many as 5 steps into their history.

I was planning on doing this using a class object:

(please ignore any previous defines like TRUE and NULL)
Code:
class HistoryObj { 
     var $label;
     var $filename;
     var $active;

     function HistoryObj() {
          $this->label = NULL;
          $this->filename = NULL;
          $this->active = FALSE;
     }
}

I need to keep track of at least those 3 variables. What I wanted to do was to create a linked list of these objects, and then store them in a session cookie if possible.

Is this the hard way of doing it?

Any suggestions? Is it possible to create a linked list of objects in PHP?

If so, is it possible to maintain the list through multiple requests via cookies or sessions?


- "Delightfully confusing..." raves The New York Times

-kas
 
I was debating on creating 5 sessions variables:

step1
step2
step3
step4
step5

and just pushing values up the list as the user progressed.

Is that a better way to do it? Just pop an object into each slot and then move them up the list accordingly?

- "Delightfully confusing..." raves The New York Times

-kas
 
PHP does not support linked lists. Those data structures require pointer math, which PHP does not support.

I think you're on the right track with multiple session variables, but why not just store the 5 values in an array? PHP has array functions which treat an array as a stack: array_push(), array_pop(), array_shift() and array_unshift(). Also, using an array gives you random access to the store.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top