4.2. PHPlot Object Serialization
Prev | Chapter 4. PHPlot Advanced Topics | Next

## 4.2. PHPlot Object Serialization

This section contains information about serializing and unserializing a PHPlot object.

Serializing a PHP variable, array, or object with the PHP function `serialize()` generates a string representation of the value which can be stored or transmitted. Unserialization with the PHP function `unserialize()` re-creates the variable, array, or object from the string representation.

Starting with PHPlot-5.8.0, PHPlot objects can be serialized and unserialized, subject to these limitations:

- A PHPlot object can only be serialized until DrawGraph is used. However, you can serialize the object, then call `DrawGraph`, if you want both the serialization and the actual plot.

- Serialization and unserialization will not work when an input file is specified in the PHPlot or PHPlot_truecolor constructors. Consider using SetBgImage instead.

- You must serialize and unserialize with the exact same version of PHPlot.

Here is an example of serializing a PHPlot object:

    require_once 'phplot.php';
    $plot = new PHPlot(800, 600);
    ... // Configure the PHPlot object: Set plot type, data values, etc.
    // Do not use DrawGraph (yet)
    $str = serialize($plot);

The corresponding unserialization looks like this:

    require_once 'phplot.php';
    $newplot = unserialize($str);
    // You can do additional plot setup here if desired.
    $newplot->DrawGraph(); // Draw it

Prev | Up | Next
Chapter 4. PHPlot Advanced Topics | Home | 4.3. Truecolor Images