__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.

When no array is returned, a TypeError is thrown.

<?php

    class WebPage {
        private $html;
        private $url;

        public function __construct($url) {
            $this->url = $url;
        }

        public function __serialize() {
            return ['url' => $url];
        }

        public function __unserialize($arg) {
            $this->url = $arg['url'];
            $this->html = file_get_contents($this->url);
        }

    }
?>

Documentation

See also 0 <`Serializing Data In PHP>`_.

Related : Unserialization, __unserialize() Method, Serialization, Serialization, Unserialization