__serialize() Method¶
The __serialize() magic method is called when a script tries to construct an associative array of key/value pairs that represent the serialized form of the object.
If no array is returned a TypeError
will be thrown.
<?php
class WebPage {
private $html;
private $url;
public function __construct($url) {
$this->url = $url;
}
public function __serialize() {
return array('url' => $url);
}
public function __unserialize($arg) {
$this->url = $arg['url'];
$this->html = file_get_contents($this->url);
}
}
?>
See also Serializing Data In PHP
Related : Unserialization, __unserialize() Method, Serialization, Serialization, Unserialization