Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

serializable(3) [php man page]

SERIALIZABLE(3) 							 1							   SERIALIZABLE(3)

The Serializable interface

INTRODUCTION
Interface for customized serializing. Classes that implement this interface no longer support __sleep() and __wakeup(). The method serialize is called whenever an instance needs to be serialized. This does not invoke __destruct() or has any other side effect unless programmed inside the method. When the data is unserialized the class is known and the appropriate unserialize() method is called as a constructor instead of calling __construct(). If you need to execute the standard constructor you may do so in the method. INTERFACE SYNOPSIS
Serializable Serializable Methods o abstractpublic string Serializable::serialize (void ) o abstractpublic void Serializable::unserialize (string $serialized) Example #1 Basic usage <?php class obj implements Serializable { private $data; public function __construct() { $this->data = "My private data"; } public function serialize() { return serialize($this->data); } public function unserialize($data) { $this->data = unserialize($data); } public function getData() { return $this->data; } } $obj = new obj; $ser = serialize($obj); var_dump($ser); $newobj = unserialize($ser); var_dump($newobj->getData()); ?> The above example will output something similar to: string(38) "C:3:"obj":23:{s:15:"My private data";}" string(15) "My private data" PHP Documentation Group SERIALIZABLE(3)

Check Out this Related Man Page

ARRAYACCESS(3)								 1							    ARRAYACCESS(3)

The ArrayAccess interface

INTRODUCTION
Interface to provide accessing objects as arrays. INTERFACE SYNOPSIS
ArrayAccess ArrayAccess Methods o abstractpublic boolean ArrayAccess::offsetExists (mixed $offset) o abstractpublic mixed ArrayAccess::offsetGet (mixed $offset) o abstractpublic void ArrayAccess::offsetSet (mixed $offset, mixed $value) o abstractpublic void ArrayAccess::offsetUnset (mixed $offset) Example #1 Basic usage <?php class obj implements ArrayAccess { private $container = array(); public function __construct() { $this->container = array( "one" => 1, "two" => 2, "three" => 3, ); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function offsetGet($offset) { return isset($this->container[$offset]) ? $this->container[$offset] : null; } } $obj = new obj; var_dump(isset($obj["two"])); var_dump($obj["two"]); unset($obj["two"]); var_dump(isset($obj["two"])); $obj["two"] = "A value"; var_dump($obj["two"]); $obj[] = 'Append 1'; $obj[] = 'Append 2'; $obj[] = 'Append 3'; print_r($obj); ?> The above example will output something similar to: bool(true) int(2) bool(false) string(7) "A value" obj Object ( [container:obj:private] => Array ( [one] => 1 [three] => 3 [two] => A value [0] => Append 1 [1] => Append 2 [2] => Append 3 ) ) PHP Documentation Group ARRAYACCESS(3)
Man Page