problem with class variables

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
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

problem with class variables

Post by duk »

im doint something wrong but cant figure what, i have this code and in the 3rd function the class variable lose is content...

Code: Select all

Class CreatePoll {
    var $options_title;
    var $options_number;

function page_1() {

   

}

function page_2() {
  echo $this->options_title;
}

function page_3() {
  //here just dont work more
   echo $this->options_title;
}

$obj_CreatePoll = New CreatePoll;


if (isset($_POST['page1'])){    
     
    $obj_CreatePoll->options_title = $_POST['blablka'];
    $obj_CreatePoll->page_2(); 
} elseif(isset($_POST['page2'])) {
    $obj_CreatePoll->page_3();   
} else {
    $obj_CreatePoll->page_1();   
}

}
thanks in advance
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

All of the class variables (properties) will "lose" their values every request. You would need to store the object or some vars in the session or pass the extra values through each form as hidden inputs.
(#10850)
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

o_O, in that case how a shooping cart works ???

now i have a big confusion in my head... so the functions additem and removeItem how they work ???

you saying that a object doesnt store information from class cariables etc.. ??? we need to go for $_SESSION ??
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Ususally the Cart object or the array of items are stored in the Session.
(#10850)
Post Reply