doni49 Posted October 11, 2006 Share Posted October 11, 2006 I DID do a search but a bunch of other junk came up. I guess I'm not using a good search parameter, but I'm drawing a blank one what WOULD be a good search. I'm trying to find out how to pass an object (a class that i created) from one page to another.Do I set a session variable equal the variable that the object is assigned to? Will the whole object be available in the next page? Is that the best way to do it or is there a better way (more efficient use of memory)?I've got a small example class below of course my REAL class will be much larger and more complicated which is why I'm asking about memory usage.[code]<?phpclass myClass{ var $test1=1; var $test2=2; var $test3; function myClass(){ $this->test3 = $this->test1 + $this->test2; }}$tstvar = new myClass;?>[/code]I'm thinking that the following would make the entire object available on the next page, but I'm not sure it's the best use of memory. Is there a better way of doing it?[code]$_SESSION['tstvar']=$tstvar;[/code]TIA! Link to comment https://forums.phpfreaks.com/topic/23664-page-object-between-pages/ Share on other sites More sharing options...
trq Posted October 11, 2006 Share Posted October 11, 2006 Yes, storing it in a sessions is [i]the[/i] way to do it. Just remember on page 2 you'll need to save it back into a local var before trying to access it. eg;[code=php:0]session_start();$obj = $_SESSION['myobj'];$a = $obj->foo();[/code]You could also use serialize / unserialize but essentually that is exactly what storing an object in a session does. Link to comment https://forums.phpfreaks.com/topic/23664-page-object-between-pages/#findComment-107419 Share on other sites More sharing options...
doni49 Posted October 11, 2006 Author Share Posted October 11, 2006 Thanks. I kinda figured that. But I wasn't sure if there was a better way to do it.I have one other Q about this. Is there a limit to the amount of data that can be passed via session? Either the session overall or the single session variable that contains this particular object. Link to comment https://forums.phpfreaks.com/topic/23664-page-object-between-pages/#findComment-107673 Share on other sites More sharing options...
trq Posted October 11, 2006 Share Posted October 11, 2006 Not that Im aware of. Link to comment https://forums.phpfreaks.com/topic/23664-page-object-between-pages/#findComment-107677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.