micmola Posted April 1, 2011 Share Posted April 1, 2011 I have created an object and assigned values as follows: $car_object =& new Car(); $car_object->offer = 'Sale'; $car_object->type = 'Sport Car'; $car_object->location = "Buffalo, New york"; How can I store the $car_object inside a session variable? How can I get the $car_object out from the session variable? Please help a novice. Urgent. Quote Link to comment https://forums.phpfreaks.com/topic/232406-storing-an-object-as-a-session/ Share on other sites More sharing options...
lastkarrde Posted April 1, 2011 Share Posted April 1, 2011 How can I store the $car_object inside a session variable? $_SESSION['car'] = $car_object; How can I get the $car_object out from the session variable? $my_old_car_object = $_SESSION['car']; $my_old_car_object->offer; //Sale Quote Link to comment https://forums.phpfreaks.com/topic/232406-storing-an-object-as-a-session/#findComment-1195646 Share on other sites More sharing options...
JasonLewis Posted April 2, 2011 Share Posted April 2, 2011 Like what was said above, however you must remember to call session_start() on all pages that will be using sessions. Quote Link to comment https://forums.phpfreaks.com/topic/232406-storing-an-object-as-a-session/#findComment-1195772 Share on other sites More sharing options...
KevinM1 Posted April 2, 2011 Share Posted April 2, 2011 Also, unless you're using PHP 4, you shouldn't use the object's reference ('&') during assignment. In PHP 5, objects are automatically passed by reference. Quote Link to comment https://forums.phpfreaks.com/topic/232406-storing-an-object-as-a-session/#findComment-1195773 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.