Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: Object


Message #1 by Rodrigob <rodrigob@l...> on 24 Jan 2003 16:30:11 -0200
> hi! how i register a session of an object????


Well, you should just be able to add the object to your $_SESSION array.

The newer versions of PHP introduce new special object methods, __sleep() and
__wakeup(), which can be use to clean things up before being serialized and
reinitialize after being unserialized.


Serialized, by the way, basically means generating a binary string
representation of an object or array.


For example:

class Person
{
   var $name;
   var $age;

   function Person($name, $age)
   {
      $this->name = $name;
      $this->age  = $age;
   }
}


$me = new Person('Nikolai', 27);

$_SESSION['me'] = $me;

}


When $me is serialized to be stored in the session, it's translated into
something like this:

"Object:Person;7Nikolai27"

(Keep in mind that the above string is not the actual representation; I just
made it up.)


Anyway, you should read up about this stuff in the OOP section of the manual:

  http://www.php.net/oop
  http://www.php.net/oop.serialization



Take care,

Nik


  Return to Index