18.5. Special functions
Précédent | Chapitre 18. Zend_Measure | Suivant

## 18.5. Special functions

To make your work easier, there are a few additional functions, which will be described below.

`Serializing and Deserializing`

`Listing all known types`

`Listing all known units`

### 18.5.1. Serializing and Deserializing

To save measurements for later use, `Zend_Measure` supports serialization.

Exemple 18.18. Serializing

    <?php
    require_once 'Zend.php';
    Zend::loadClass('Zend_Measure');

    $unit = new Zend_Measure(100,Zend_Measure::LENGTH);

    $serial = $unit->serialize();

    // save ... or any other action
    ?>

Exemple 18.19. Deserializing

    <?php
    require_once 'Zend.php';
    Zend::loadClass('Zend_Measure');
    Zend::loadClass('Zend_Measure_Length');

    // load serialized object

    $unit = unserialize($serial);

    echo $unit;
    ?>

### 18.5.2. Listing all known types

The function `getAllTypes` returns an array containing all types of measurement.

This could be used to let a user choose the type of measurement (length, weight, area) he wishes to input.

### 18.5.3. Listing all known units

The function `getTypeList` returns an array containing all units of measurement for a given type.

This could be used to let a user choose the unit of measurement (meters, kilometers, millimeters,...) for his input.

Exemple 18.20. Listing all units for a given type

    <?php
    require_once 'Zend.php';
    Zend::loadClass('Zend_Measure');
    Zend::loadClass('Zend_Measure_Length');

    $unit = new Zend_Measure(0,Zend_Measure::LENGTH);

    $array = $unit->getTypeList();
    print_r($array);
    ?>

Précédent | Niveau supérieur | Suivant
18.4. Manipulating measurements | Sommaire | 18.6. Types of measurements