Jump to content

Recommended Posts

I use PHP 5.1.4 and need the session to save objects in it.

 

An abstract example:

 

class House{
  public $objRoom = array();
  public $objType;

  public __construct(){
   $this->objRoom[] = new Room();
   $this->objType = new HType();
  }

  public addRoom(){
   $this->objRoom[] = new Room();
  }
}

class Room{
  public $name;
  public $size;

  public __construct(){
  }
  public setName($name){
   $this->name = $name;
  }
}

class HType{
...
}

 

Firstly, after successfully logon I register my object like that:

 

ini_set("session.use_trans_sid",true);
session_start();

autoloader for classes...

$_SESSION['myHouse'] = new House();

 

And then, I open a new window with javascript and close the previous. I open a file looks like as follows

 

<?php
ini_set("session.use_trans_sid",true);
session_start();

here comes the autoloader for the classes...

if(isset($_GET['act']) AND $_GET['act']=="addRoom"){
$_SESSION['myHouse']->addRoom();
}

if(isset($_GET['name']) AND $_isset($_GET['act']) AND $_GET['act']=="setRoomName"){
  $_SESSION['myHouse']->objRoom[$objRef]->setName($_GET['name']);
}

?>
<html>

.... some code


</html>

 

While I add and delete rooms or change their names I loose the content of the session. All my objects are disappeared and the session file is empty!

 

 

I activated errror_reporting(EALL) at the beginning of each page. I get only an error message when the object myHouse is disappeared.

 

 

What wrong do I make?

Link to comment
https://forums.phpfreaks.com/topic/64754-session-problems-with-objects/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.