haku87 Posted October 27, 2007 Share Posted October 27, 2007 I know that in JSP, there are such things known as bean to store data from one page to another. Another alternative to beam will be using SESSION object. In php 5, OOP concept was introduced. I read up alot of it. I will like to know the following answer. $a = new object(); The reference variable $a which has been created only exist on the current page, or current session. Is there a way to pass data from a page to another page without using SESSION object Ande Thanks Quote Link to comment https://forums.phpfreaks.com/topic/74992-php-classes-and-serialization/ Share on other sites More sharing options...
MadTechie Posted October 27, 2007 Share Posted October 27, 2007 you could use a temp file, cookies, database, GET/POST.. maybe eaiser to help if we know what your attemping to do Quote Link to comment https://forums.phpfreaks.com/topic/74992-php-classes-and-serialization/#findComment-379229 Share on other sites More sharing options...
toplay Posted October 27, 2007 Share Posted October 27, 2007 Save yourself a lot of time and just use sessions. Like on most web applications, the choices of passing data from one area to another are: saving in server memory saving on server disk (flat file, sessions which default to using flat files, or database) GET POST Cookies (saving on client disk) Object serialization: http://us3.php.net/manual/en/language.oop.serialization.php In PHP5 your example, variable $a can be assigned to a session variable (i.e. $_SESSION['a'] = $a;) and PHP will automatically serialize and unserialize for you. The definition of the class (i.e. object() in this case) must be defined first before issuing a session_start(). hth. EDIT: MadTechie beat me to it. Quote Link to comment https://forums.phpfreaks.com/topic/74992-php-classes-and-serialization/#findComment-379235 Share on other sites More sharing options...
MadTechie Posted October 27, 2007 Share Posted October 27, 2007 My Post = Quick and Cheap toplay Post = nicely done.. Quote Link to comment https://forums.phpfreaks.com/topic/74992-php-classes-and-serialization/#findComment-379239 Share on other sites More sharing options...
haku87 Posted October 27, 2007 Author Share Posted October 27, 2007 From what i read from object serialization. It is just converting an object or large array data into a string. $a = new object(); $b=serialize($a); In such case, $b will still be destroy once it leave the page unless $_SESSION[abc] = $b; is used? Most application i programmed required me to pass argument from one page to another page only. I realized i has been using alot of session variable. Another fact is that I was using structured style to program my application. I was wondering wat is the life span of the object created. eg. include class.php; $a = new object(); assume class.php contain the object class that i need. Does it mean that everytime i used this class. I need to include it in every page. Quote Link to comment https://forums.phpfreaks.com/topic/74992-php-classes-and-serialization/#findComment-379250 Share on other sites More sharing options...
toplay Posted October 27, 2007 Share Posted October 27, 2007 In such case, $b will still be destroy once it leave the page unless $_SESSION[abc] = $b; is used? Yes, that's correct. It must be saved in one of the ways I've already described. One of the reasons I showed you serialize, is because that's a way to pass something to the next page in a (GET/POST) like in a hidden form field. This is not recommended especially if you have sensitive information being saved and passed. I'm just explaining that it's possible because you asked for the ways it could be done. Another fact is that I was using structured style to program my application. I was wondering wat is the life span of the object created. eg. include class.php; $a = new object(); assume class.php contain the object class that i need. Does it mean that everytime i used this class. I need to include it in every page. Yes, class.php would have to be required every time on the pages where you wish to retrieve that data, and the class must be defined/included first before issuing a session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/74992-php-classes-and-serialization/#findComment-379367 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.