Page 1 of 1

problem with class variables

Posted: Mon Jul 03, 2006 1:26 pm
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

Posted: Mon Jul 03, 2006 1:42 pm
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.

Posted: Mon Jul 03, 2006 1:50 pm
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 ??

Posted: Mon Jul 03, 2006 1:53 pm
by Christopher
Ususally the Cart object or the array of items are stored in the Session.